Skip to content

Commit a9bc1c7

Browse files
committed
Merge rust-bitcoin#3605: Mark function as const
1db4b72 Mark function as const (yancy) Pull request description: We discussed marking from_vb as const here: rust-bitcoin#3602 However, from what I can tell, map() isn't const and I don't see a tracking issue for changing it. Also, the question mark operator isn't available in const context either, although there is a tracking issue for that: rust-lang/rust#74935. It will be a long while before that makes it into this projects MSRV if/when it lands. There are some other functions in this module that could use the same re-write to make them const as well it looks like. ACKs for top commit: tcharding: ACK 1db4b72 apoelstra: ACK 1db4b72; successfully ran local tests Tree-SHA512: 62b612791dd3ce2f6ebf27f586a1262633a46566b9fd3583984171f62209714ad979439345fe86d8ef87d2f78a2cee21d619e2eb3621689faf59d81640e9f77c
2 parents 7085223 + 1db4b72 commit a9bc1c7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

units/src/weight.rs

Lines changed: 6 additions & 2 deletions
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)