Add from_wu_usize to Weight type
This commit is contained in:
parent
1a88c887f5
commit
77552987ab
|
@ -40,6 +40,9 @@ impl Weight {
|
||||||
/// Directly constructs `Weight` from weight units.
|
/// Directly constructs `Weight` from weight units.
|
||||||
pub const fn from_wu(wu: u64) -> Self { Weight(wu) }
|
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.
|
/// 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) }
|
pub fn from_kwu(wu: u64) -> Option<Self> { wu.checked_mul(1000).map(Weight) }
|
||||||
|
|
||||||
|
@ -110,6 +113,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn weight_constructor_test() {
|
fn weight_constructor_test() {
|
||||||
assert_eq!(Weight::ZERO, Weight::from_wu(0));
|
assert_eq!(Weight::ZERO, Weight::from_wu(0));
|
||||||
|
assert_eq!(Weight::ZERO, Weight::from_wu_usize(0_usize));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue