From 1db4b723dc59568c14c76598e7c63c58651ed1cd Mon Sep 17 00:00:00 2001 From: yancy Date: Tue, 12 Nov 2024 12:54:45 -0600 Subject: [PATCH] Mark function as const --- units/src/weight.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/units/src/weight.rs b/units/src/weight.rs index b43d76341..351dfd646 100644 --- a/units/src/weight.rs +++ b/units/src/weight.rs @@ -55,8 +55,12 @@ impl Weight { pub fn from_kwu(wu: u64) -> Option { 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 { - vb.checked_mul(Self::WITNESS_SCALE_FACTOR).map(Weight::from_wu) + pub const fn from_vb(vb: u64) -> Option { + // 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.