Skip to content

Commit 1db4b72

Browse files
committed
Mark function as const
1 parent 73e33e5 commit 1db4b72

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: units/src/weight.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ impl Weight {
5555
pub fn from_kwu(wu: u64) -> Option<Self> { wu.checked_mul(1000).map(Weight) }
5656

5757
/// Constructs a new [`Weight`] from virtual bytes, returning [`None`] if an overflow occurred.
58-
pub fn from_vb(vb: u64) -> Option<Self> {
59-
vb.checked_mul(Self::WITNESS_SCALE_FACTOR).map(Weight::from_wu)
58+
pub const fn from_vb(vb: u64) -> Option<Self> {
59+
// No `map()` in const context.
60+
match vb.checked_mul(Self::WITNESS_SCALE_FACTOR) {
61+
Some(wu) => Some(Weight::from_wu(wu)),
62+
None => None,
63+
}
6064
}
6165

6266
/// Constructs a new [`Weight`] from virtual bytes panicking if an overflow occurred.

0 commit comments

Comments
 (0)