Skip to content

Commit

Permalink
Format code using rustfmt
Browse files Browse the repository at this point in the history
With this change we format the code of the crate according to rustfmt.
Along with that we check in our rustfmt configuration, so that it will
automatically be made available and picked up when the repository is
cloned.
  • Loading branch information
d-e-s-o committed Oct 19, 2021
1 parent eb14fa4 commit 59f0145
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased
----------
- Formatted code base using `rustfmt` and checked in configuration


0.1.3
-----
- Added support for generating completion scripts for shells other than
Expand Down
7 changes: 7 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
blank_lines_lower_bound = 0
blank_lines_upper_bound = 2
edition = "2018"
imports_layout = "Vertical"
match_block_trailing_comma = true
tab_spaces = 2
trailing_semicolon = false
44 changes: 27 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#![type_length_limit = "536870912"]
#![allow(
clippy::large_enum_variant,
clippy::let_and_return,
)]
#![allow(clippy::large_enum_variant, clippy::let_and_return)]

mod args;

Expand Down Expand Up @@ -111,7 +108,8 @@ fn format_account_status(status: account::Status) -> String {
account::Status::Active => "active",
account::Status::Rejected => "rejected",
account::Status::Unknown => "unknown",
}.to_string()
}
.to_string()
}


Expand All @@ -131,7 +129,8 @@ async fn account_get(client: Client) -> Result<(), Error> {
.await
.with_context(|| "failed to retrieve account information")?;

println!(r#"account:
println!(
r#"account:
id: {id}
status: {status}
buying power: {buying_power}
Expand Down Expand Up @@ -268,7 +267,8 @@ async fn account_activity_get(client: Client) -> Result<(), Error> {
for activity in activities {
match activity {
account_activities::Activity::Trade(trade) => {
println!(r#"{time} {side} {qty} {sym} @ {price} = {total}"#,
println!(
r#"{time} {side} {qty} {sym} @ {price} = {total}"#,
time = format_local_time_short(trade.transaction_time),
side = format_activity_side(trade.side),
qty = trade.quantity,
Expand All @@ -278,7 +278,8 @@ async fn account_activity_get(client: Client) -> Result<(), Error> {
);
},
account_activities::Activity::NonTrade(non_trade) => {
println!(r#"{date:19} {activity} {amount}"#,
println!(
r#"{date:19} {activity} {amount}"#,
date = format_date(non_trade.date),
activity = format_activity_type(non_trade.type_),
amount = format_price(&non_trade.net_amount, &currency),
Expand Down Expand Up @@ -314,7 +315,8 @@ async fn account_config_get(client: Client) -> Result<(), Error> {
.await
.with_context(|| "failed to retrieve account configuration")?;

println!(r#"account configuration:
println!(
r#"account configuration:
trade confirmation: {trade_confirmation}
trading suspended: {trading_suspended}
shorting enabled: {shorting}"#,
Expand Down Expand Up @@ -385,7 +387,8 @@ async fn asset_get(client: Client, symbol: Symbol) -> Result<(), Error> {
.await
.with_context(|| format!("failed to retrieve asset information for {}", symbol.0))?;

println!(r#"{sym}:
println!(
r#"{sym}:
id: {id}
asset class: {cls}
exchange: {exchg}
Expand Down Expand Up @@ -488,7 +491,8 @@ async fn stream_account_updates(client: Client, json: bool) -> Result<(), Error>
.map_err(Error::from)
.try_for_each(|result| async {
let update = result.unwrap();
println!(r#"account update:
println!(
r#"account update:
status: {status}
created at: {created}
updated at: {updated}
Expand Down Expand Up @@ -636,7 +640,8 @@ async fn stream_trade_updates(client: Client, json: bool) -> Result<(), Error> {
.map_err(Error::from)
.try_for_each(|result| async {
let update = result.unwrap();
println!(r#"{symbol} {status}:
println!(
r#"{symbol} {status}:
order id: {id}
status: {order_status}
type: {type_}
Expand Down Expand Up @@ -677,7 +682,8 @@ async fn market(client: Client) -> Result<(), Error> {
.await
.with_context(|| "failed to retrieve market clock")?;

println!(r#"market:
println!(
r#"market:
open: {open}
current time: {current}
next open: {next_open}
Expand Down Expand Up @@ -874,7 +880,8 @@ async fn order_change(client: Client, change: ChangeOrder) -> Result<(), Error>
limit_price,
stop_price,
..Default::default()
}.init();
}
.init();

let order = client
.issue::<order::Patch>(&(id.0, request))
Expand Down Expand Up @@ -943,7 +950,8 @@ async fn order_get(client: Client, id: OrderId) -> Result<(), Error> {
.collect::<Vec<_>>()
.join(",");

println!(r#"{sym}:
println!(
r#"{sym}:
order id: {id}
status: {status}
created at: {created}
Expand Down Expand Up @@ -1133,7 +1141,8 @@ async fn position_get(client: Client, symbol: Symbol) -> Result<(), Error> {
let position =
position.with_context(|| format!("failed to retrieve position for {}", symbol.0))?;

println!(r#"{sym}:
println!(
r#"{sym}:
asset id: {id}
exchange: {exchg}
avg entry: {entry}
Expand Down Expand Up @@ -1176,7 +1185,8 @@ async fn position_close(client: Client, symbol: Symbol) -> Result<(), Error> {
.currency;
let order = order.with_context(|| format!("failed to liquidate position for {}", symbol.0))?;

println!(r#"{sym}:
println!(
r#"{sym}:
order id: {id}
status: {status}
quantity: {quantity}
Expand Down
5 changes: 1 addition & 4 deletions utils/shell-complete.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Copyright (C) 2020-2021 Daniel Mueller <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later

#![allow(
clippy::large_enum_variant,
clippy::let_and_return,
)]
#![allow(clippy::large_enum_variant, clippy::let_and_return)]

use std::io::stdout;

Expand Down

0 comments on commit 59f0145

Please sign in to comment.