From 1fe984552e0a691c836136a82fe1733cea4f0763 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 3 Mar 2025 13:44:14 +1100 Subject: [PATCH 1/2] Improve Weight rustdocs Do trivial improvement to rustdocs for the `Weight` type. --- units/src/weight.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/units/src/weight.rs b/units/src/weight.rs index 720dfd385..c7fb19913 100644 --- a/units/src/weight.rs +++ b/units/src/weight.rs @@ -12,10 +12,10 @@ use serde::{Deserialize, Serialize}; /// The factor that non-witness serialization data is multiplied by during weight calculation. pub const WITNESS_SCALE_FACTOR: usize = 4; -/// Represents block weight - the weight of a transaction or block. +/// Represents weight - the weight of a transaction or block. /// /// This is an integer newtype representing [`Weight`] in `wu`. It provides protection against mixing -/// up the types as well as basic formatting features. +/// up types as well as basic formatting features. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(transparent))] From 2434afc40dadd213f8695c5ce91d397c03f337be Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 3 Mar 2025 13:46:42 +1100 Subject: [PATCH 2/2] Make Weigth::from_kwu const The other two `Weight` constructors are const already. --- units/src/weight.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/units/src/weight.rs b/units/src/weight.rs index c7fb19913..ecd50b804 100644 --- a/units/src/weight.rs +++ b/units/src/weight.rs @@ -48,7 +48,13 @@ impl Weight { pub const fn from_wu(wu: u64) -> Self { Weight(wu) } /// Constructs a new [`Weight`] from kilo weight units returning [`None`] if an overflow occurred. - pub fn from_kwu(wu: u64) -> Option { wu.checked_mul(1000).map(Weight) } + pub const fn from_kwu(wu: u64) -> Option { + // No `map()` in const context. + match wu.checked_mul(1000) { + Some(wu) => Some(Weight::from_wu(wu)), + None => None, + } + } /// Constructs a new [`Weight`] from virtual bytes, returning [`None`] if an overflow occurred. pub const fn from_vb(vb: u64) -> Option {