Skip to content

Commit ee926a1

Browse files
wboayueWil Boayue
and
Wil Boayue
authored
cleanup warnings (#114)
Co-authored-by: Wil Boayue <[email protected]>
1 parent 463daf9 commit ee926a1

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

src/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ fn parse_connection_time(connection_time: &str) -> (Option<OffsetDateTime>, Opti
993993
},
994994
Err(err) => {
995995
error!("could not parse connection time from {date_str}: {err}");
996-
return (None, Some(timezone));
996+
(None, Some(timezone))
997997
}
998998
}
999999
}

src/orders.rs

+33-27
Original file line numberDiff line numberDiff line change
@@ -600,14 +600,16 @@ impl ToField for Action {
600600
}
601601
}
602602

603-
impl ToString for Action {
604-
fn to_string(&self) -> String {
605-
match self {
606-
Action::Buy => String::from("BUY"),
607-
Action::Sell => String::from("SELL"),
608-
Action::SellShort => String::from("SSHORT"),
609-
Action::SellLong => String::from("SLONG"),
610-
}
603+
impl std::fmt::Display for Action {
604+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
605+
let text = match self {
606+
Action::Buy => "BUY",
607+
Action::Sell => "SELL",
608+
Action::SellShort => "SSHORT",
609+
Action::SellLong => "SLONG",
610+
};
611+
612+
write!(f, "{text}")
611613
}
612614
}
613615

@@ -657,19 +659,21 @@ impl ToField for Option<Rule80A> {
657659
}
658660
}
659661

660-
impl ToString for Rule80A {
661-
fn to_string(&self) -> String {
662-
match self {
663-
Rule80A::Individual => String::from('I'),
664-
Rule80A::Agency => String::from('A'),
665-
Rule80A::AgentOtherMember => String::from('W'),
666-
Rule80A::IndividualPTIA => String::from('J'),
667-
Rule80A::AgencyPTIA => String::from('U'),
668-
Rule80A::AgentOtherMemberPTIA => String::from('M'),
669-
Rule80A::IndividualPT => String::from('K'),
670-
Rule80A::AgencyPT => String::from('Y'),
671-
Rule80A::AgentOtherMemberPT => String::from('N'),
672-
}
662+
impl std::fmt::Display for Rule80A {
663+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
664+
let text = match self {
665+
Rule80A::Individual => "I",
666+
Rule80A::Agency => "A",
667+
Rule80A::AgentOtherMember => "W",
668+
Rule80A::IndividualPTIA => "J",
669+
Rule80A::AgencyPTIA => "U",
670+
Rule80A::AgentOtherMemberPTIA => "M",
671+
Rule80A::IndividualPT => "K",
672+
Rule80A::AgencyPT => "Y",
673+
Rule80A::AgentOtherMemberPT => "N",
674+
};
675+
676+
write!(f, "{text}")
673677
}
674678
}
675679

@@ -816,12 +820,14 @@ impl ToField for Option<OrderOpenClose> {
816820
}
817821
}
818822

819-
impl ToString for OrderOpenClose {
820-
fn to_string(&self) -> String {
821-
match self {
822-
OrderOpenClose::Open => String::from("O"),
823-
OrderOpenClose::Close => String::from("C"),
824-
}
823+
impl std::fmt::Display for OrderOpenClose {
824+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
825+
let text = match self {
826+
OrderOpenClose::Open => "O",
827+
OrderOpenClose::Close => "C",
828+
};
829+
830+
write!(f, "{text}")
825831
}
826832
}
827833

src/orders/order_builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ pub fn attach_adjustable_to_trail(
786786

787787
order.parent_id = parent.order_id;
788788
order.trigger_price = Some(trigger_price); // When trigger price is penetrated
789-
order.adjusted_order_type = "TRAIL".to_owned(); // The parent order will be turned into a TRAIL order
789+
"TRAIL".clone_into(&mut order.adjusted_order_type); // The parent order will be turned into a TRAIL order
790790
order.adjusted_stop_price = Some(adjusted_stop_price); // With a stop price of ...
791791
order.adjustable_trailing_unit = trail_unit; // trailing by and amount (0) or a percent (100) ...
792792
order.adjusted_trailing_amount = Some(adjusted_trail_amount); // of ...
@@ -915,7 +915,7 @@ pub fn limit_ibkrats(action: Action, quantity: f64, limit_price: f64) -> Order {
915915

916916
pub fn limit_order_with_manual_order_time(action: Action, quantity: f64, limit_price: f64, manual_order_time: &str) -> Order {
917917
let mut order = limit_order(action, quantity, limit_price);
918-
order.manual_order_time = manual_order_time.to_owned();
918+
manual_order_time.clone_into(&mut order.manual_order_time);
919919

920920
order
921921
}

0 commit comments

Comments
 (0)