From 77552987ab3cf010b326fdba90d2aa5676349161 Mon Sep 17 00:00:00 2001 From: yancy Date: Fri, 25 Aug 2023 09:35:19 +0200 Subject: [PATCH] Add from_wu_usize to Weight type --- bitcoin/src/blockdata/weight.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bitcoin/src/blockdata/weight.rs b/bitcoin/src/blockdata/weight.rs index e88e9f4f..03664111 100644 --- a/bitcoin/src/blockdata/weight.rs +++ b/bitcoin/src/blockdata/weight.rs @@ -40,6 +40,9 @@ impl Weight { /// Directly constructs `Weight` from weight units. pub const fn from_wu(wu: u64) -> Self { Weight(wu) } + /// Directly constructs `Weight` from usize weight units. + pub const fn from_wu_usize(wu: usize) -> Self { Weight(wu as u64) } + /// Constructs `Weight` from kilo weight units returning `None` if an overflow occurred. pub fn from_kwu(wu: u64) -> Option { wu.checked_mul(1000).map(Weight) } @@ -110,6 +113,7 @@ mod tests { #[test] fn weight_constructor_test() { assert_eq!(Weight::ZERO, Weight::from_wu(0)); + assert_eq!(Weight::ZERO, Weight::from_wu_usize(0_usize)); } #[test]