Mark function as const

This commit is contained in:
yancy 2024-11-12 12:54:45 -06:00
parent 73e33e5808
commit 1db4b723dc
1 changed files with 6 additions and 2 deletions

View File

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