Make Weigth::from_kwu const

The other two `Weight` constructors are const already.
This commit is contained in:
Tobin C. Harding 2025-03-03 13:46:42 +11:00
parent 1fe984552e
commit 2434afc40d
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 7 additions and 1 deletions

View File

@ -48,7 +48,13 @@ impl Weight {
pub const fn from_wu(wu: u64) -> Self { Weight(wu) }
/// Constructs a new [`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 const fn from_kwu(wu: u64) -> Option<Self> {
// No `map()` in const context.
match wu.checked_mul(1000) {
Some(wu) => Some(Weight::from_wu(wu)),
None => None,
}
}
/// Constructs a new [`Weight`] from virtual bytes, returning [`None`] if an overflow occurred.
pub const fn from_vb(vb: u64) -> Option<Self> {