Skip to content

Commit

Permalink
refactor: remove Fraction type and use fraction crate
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed Jun 15, 2022
1 parent 611df64 commit db783e2
Showing 7 changed files with 81 additions and 242 deletions.
3 changes: 2 additions & 1 deletion sdk/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ serde = { version = "1.0.137", features = ["derive"] }
thiserror = "1.0.31"
time = { version = "0.3.9", features = ["serde"] }
tokio = { version = "1.18.1", features = ["rt-multi-thread"] }
hedera-proto = { path = "./protobufs", features = ["serde", "time_0_3"] }
hedera-proto = { path = "./protobufs", features = ["serde", "time_0_3", "fraction"] }
serde_json = "1.0.79"
serde_with = { version = "1.12.1", features = ["hex", "base64", "time_0_3"] }
tonic = { version = "0.7.1", features = ["compression"] }
@@ -40,6 +40,7 @@ k256 = "0.11.0"
pkcs8 = "0.9.0"
async-stream = "0.3.3"
futures-core = "0.3.21"
fraction = { version = "0.10.0", features = ["with-serde-support"] }

[dev-dependencies]
anyhow = "1.0.57"
1 change: 1 addition & 0 deletions sdk/rust/protobufs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ serde = { version = "1.0.136", features = [ "derive" ], optional = true }
chrono_0_4 = { version = "0.4.19", optional = true, package = "chrono" }
time_0_2 = { version = "0.2.27", optional = true, package = "time" }
time_0_3 = { version = "0.3.9", optional = true, package = "time" }
fraction = { version = "0.10.0", optional = true }

[build-dependencies]
anyhow = "1.0.55"
16 changes: 16 additions & 0 deletions sdk/rust/protobufs/src/fraction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use fraction::Fraction;

impl From<super::services::Fraction> for Fraction {
fn from(pb: super::services::Fraction) -> Self {
Fraction::new(pb.numerator as u64, pb.denominator as u64)
}
}

impl From<Fraction> for super::services::Fraction {
fn from(frac: Fraction) -> Self {
Self {
numerator: frac.numer().copied().unwrap_or_default() as i64,
denominator: frac.denom().copied().unwrap_or_default() as i64,
}
}
}
3 changes: 3 additions & 0 deletions sdk/rust/protobufs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@ mod time_0_2;
#[cfg(feature = "time_0_3")]
mod time_0_3;

#[cfg(feature = "fraction")]
mod fraction;

pub mod services {
tonic::include_proto!("proto");
}
121 changes: 0 additions & 121 deletions sdk/rust/src/fraction.rs

This file was deleted.

1 change: 0 additions & 1 deletion sdk/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ mod entity_id;
mod error;
mod execute;
mod file;
mod fraction;
mod key;
mod mirror_query;
mod node_address;
Loading

0 comments on commit db783e2

Please sign in to comment.