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]