From a9263c4a501d614261ab0d020f8d895562d8f81b Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Thu, 14 Mar 2024 12:13:09 -0400 Subject: [PATCH] =?UTF-8?q?feat(num):=20=E2=9C=A8=20`Amount`=20is=20`From`=20and=20`From`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this expands on the existing `u32` and `u64` implementations, which themselves delegate down to `u128`. https://doc.rust-lang.org/stable/std/primitive.u128.html#impl-From%3Cu16%3E-for-u128 https://doc.rust-lang.org/stable/std/primitive.u128.html#impl-From%3Cu8%3E-for-u128 --- crates/core/num/src/amount.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/core/num/src/amount.rs b/crates/core/num/src/amount.rs index 537e5fccd9..c5e47afe67 100644 --- a/crates/core/num/src/amount.rs +++ b/crates/core/num/src/amount.rs @@ -340,6 +340,22 @@ impl From for Amount { } } +impl From for Amount { + fn from(amount: u16) -> Amount { + Amount { + inner: amount as u128, + } + } +} + +impl From for Amount { + fn from(amount: u8) -> Amount { + Amount { + inner: amount as u128, + } + } +} + impl From for f64 { fn from(amount: Amount) -> f64 { amount.inner as f64