Add from_wu_usize to Weight type

This commit is contained in:
yancy 2023-08-25 09:35:19 +02:00
parent 1a88c887f5
commit 77552987ab
1 changed files with 4 additions and 0 deletions

View File

@ -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<Self> { 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]