fcc4c40a1c Rename from_vb_const (yancy)

Pull request description:

  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.

ACKs for top commit:
  apoelstra:
    ACK fcc4c40a1c
  Kixunil:
    ACK fcc4c40a1c

Tree-SHA512: 62bbd61800e9f29768d884dbe3bca14fea9b51b8f413131e0f29bfc0f0d0e20631d30489e078cc948f2dba0c5d7d9d7c229b4bb7187faef23083a88337efb6a6
This commit is contained in:
Andrew Poelstra 2023-11-28 19:44:22 +00:00
commit 8d32a49ac1
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
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) vb.checked_mul(Self::WITNESS_SCALE_FACTOR).map(Weight::from_wu)
} }
/// Constructs `Weight` from virtual bytes in const context. /// Constructs `Weight` from virtual bytes panicking on overflow.
pub const fn from_vb_const(vb: u64) -> Weight { ///
/// # 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) { match vb.checked_mul(Self::WITNESS_SCALE_FACTOR) {
Some(weight) => Weight(weight), Some(weight) => Weight(weight),
None => { None => {
@ -167,7 +171,7 @@ mod tests {
#[test] #[test]
fn from_vb_const() { 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); assert_eq!(Weight(4), WU);
} }