Rename from_vb_const

The new function is more clear because the purpose of the function is to
return a value that doesn't need to be unwrapped.  The current MSRV does
not allow unwrap() in const context.
This commit is contained in:
yancy 2023-11-27 08:59:18 +01:00
parent cfa6768e79
commit fcc4c40a1c
1 changed files with 7 additions and 3 deletions

View File

@ -54,8 +54,12 @@ impl Weight {
vb.checked_mul(Self::WITNESS_SCALE_FACTOR).map(Weight::from_wu)
}
/// Constructs `Weight` from virtual bytes in const context.
pub const fn from_vb_const(vb: u64) -> Weight {
/// Constructs `Weight` from virtual bytes panicking on overflow.
///
/// # Panics
///
/// If the conversion from virtual bytes overflows.
pub const fn from_vb_unwrap(vb: u64) -> Weight {
match vb.checked_mul(Self::WITNESS_SCALE_FACTOR) {
Some(weight) => Weight(weight),
None => {
@ -167,7 +171,7 @@ mod tests {
#[test]
fn from_vb_const() {
const WU: Weight = Weight::from_vb_const(1);
const WU: Weight = Weight::from_vb_unwrap(1);
assert_eq!(Weight(4), WU);
}