diff --git a/units/src/block.rs b/units/src/block.rs index c4a02cd9a..c7e61ce80 100644 --- a/units/src/block.rs +++ b/units/src/block.rs @@ -87,13 +87,13 @@ impl BlockHeight { /// Returns block height as a `u32`. pub const fn to_u32(self) -> u32 { self.0 } - /// Attempt to subtract two [`BlockHeight`]s, returning `None` in case of overflow. + /// Attempt to subtract two [`BlockHeight`]s, returning `None` if overflow occurred. #[must_use] pub fn checked_sub(self, other: Self) -> Option { self.0.checked_sub(other.0).map(BlockHeightInterval) } - /// Attempt to add an interval to this [`BlockHeight`], returning `None` in case of overflow. + /// Attempt to add an interval to this [`BlockHeight`], returning `None` if overflow occurred. #[must_use] pub fn checked_add(self, other: BlockHeightInterval) -> Option { self.0.checked_add(other.0).map(Self) @@ -148,11 +148,11 @@ impl BlockHeightInterval { /// Returns block interval as a `u32`. pub const fn to_u32(self) -> u32 { self.0 } - /// Attempt to subtract two [`BlockHeightInterval`]s, returning `None` in case of overflow. + /// Attempt to subtract two [`BlockHeightInterval`]s, returning `None` if overflow occurred. #[must_use] pub fn checked_sub(self, other: Self) -> Option { self.0.checked_sub(other.0).map(Self) } - /// Attempt to add two [`BlockHeightInterval`]s, returning `None` in case of overflow. + /// Attempt to add two [`BlockHeightInterval`]s, returning `None` if overflow occurred. #[must_use] pub fn checked_add(self, other: Self) -> Option { self.0.checked_add(other.0).map(Self) } } @@ -220,13 +220,13 @@ impl BlockMtp { Self::from_u32(u32::from(timestamps[5])) } - /// Attempt to subtract two [`BlockMtp`]s, returning `None` in case of overflow. + /// Attempt to subtract two [`BlockMtp`]s, returning `None` if overflow occurred. #[must_use] pub fn checked_sub(self, other: Self) -> Option { self.0.checked_sub(other.0).map(BlockMtpInterval) } - /// Attempt to add an interval to this [`BlockMtp`], returning `None` in case of overflow. + /// Attempt to add an interval to this [`BlockMtp`], returning `None` if overflow occurred. #[must_use] pub fn checked_add(self, other: BlockMtpInterval) -> Option { self.0.checked_add(other.0).map(Self) @@ -313,11 +313,11 @@ impl BlockMtpInterval { relative::NumberOf512Seconds::from_seconds_ceil(self.to_u32()) } - /// Attempt to subtract two [`BlockMtpInterval`]s, returning `None` in case of overflow. + /// Attempt to subtract two [`BlockMtpInterval`]s, returning `None` if overflow occurred. #[must_use] pub fn checked_sub(self, other: Self) -> Option { self.0.checked_sub(other.0).map(Self) } - /// Attempt to add two [`BlockMtpInterval`]s, returning `None` in case of overflow. + /// Attempt to add two [`BlockMtpInterval`]s, returning `None` if overflow occurred. #[must_use] pub fn checked_add(self, other: Self) -> Option { self.0.checked_add(other.0).map(Self) } } diff --git a/units/src/fee_rate/mod.rs b/units/src/fee_rate/mod.rs index c2ee6f4b9..f0db11cf0 100644 --- a/units/src/fee_rate/mod.rs +++ b/units/src/fee_rate/mod.rs @@ -52,7 +52,8 @@ impl FeeRate { /// The fee rate used to compute dust amount. pub const DUST: FeeRate = FeeRate::from_sat_per_vb_u32(3); - /// Constructs a new [`FeeRate`] from satoshis per 1000 weight units. + /// Constructs a new [`FeeRate`] from satoshis per 1000 weight units, + /// returning `None` if overflow occurred. pub const fn from_sat_per_kwu(sat_kwu: u64) -> Option { // No `map()` in const context. match sat_kwu.checked_mul(4_000) { @@ -61,11 +62,8 @@ impl FeeRate { } } - /// Constructs a new [`FeeRate`] from satoshis per virtual bytes. - /// - /// # Errors - /// - /// Returns [`None`] on arithmetic overflow. + /// Constructs a new [`FeeRate`] from satoshis per virtual bytes, + /// returning `None` if overflow occurred. pub const fn from_sat_per_vb(sat_vb: u64) -> Option { // No `map()` in const context. match sat_vb.checked_mul(1_000_000) { @@ -80,7 +78,8 @@ impl FeeRate { FeeRate::from_sat_per_mvb(sat_vb * 1_000_000) } - /// Constructs a new [`FeeRate`] from satoshis per kilo virtual bytes (1,000 vbytes). + /// Constructs a new [`FeeRate`] from satoshis per kilo virtual bytes (1,000 vbytes), + /// returning `None` if overflow occurred. pub const fn from_sat_per_kvb(sat_kvb: u64) -> Option { // No `map()` in const context. match sat_kvb.checked_mul(1_000) { @@ -109,7 +108,7 @@ impl FeeRate { /// Checked multiplication. /// - /// Computes `self * rhs` returning [`None`] if overflow occurred. + /// Computes `self * rhs`, returning [`None`] if overflow occurred. #[must_use] pub const fn checked_mul(self, rhs: u64) -> Option { // No `map()` in const context. @@ -133,7 +132,7 @@ impl FeeRate { /// Checked addition. /// - /// Computes `self + rhs` returning [`None`] if overflow occurred. + /// Computes `self + rhs` returning [`None`] is case of overflow. #[must_use] pub const fn checked_add(self, rhs: FeeRate) -> Option { // No `map()` in const context. @@ -145,7 +144,7 @@ impl FeeRate { /// Checked subtraction. /// - /// Computes `self - rhs` returning [`None`] if overflow occurred. + /// Computes `self - rhs`, returning [`None`] if overflow occurred. #[must_use] pub const fn checked_sub(self, rhs: FeeRate) -> Option { // No `map()` in const context. diff --git a/units/src/locktime/absolute.rs b/units/src/locktime/absolute.rs index cfbce396b..73102af8d 100644 --- a/units/src/locktime/absolute.rs +++ b/units/src/locktime/absolute.rs @@ -114,7 +114,7 @@ impl fmt::Display for ParseHeightError { #[cfg(feature = "std")] impl std::error::Error for ParseHeightError { - // To be consistent with `write_err` we need to **not** return source in case of overflow + // To be consistent with `write_err` we need to **not** return source if overflow occurred fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { self.0.source() } } @@ -239,7 +239,7 @@ impl fmt::Display for ParseTimeError { #[cfg(feature = "std")] impl std::error::Error for ParseTimeError { - // To be consistent with `write_err` we need to **not** return source in case of overflow + // To be consistent with `write_err` we need to **not** return source if overflow occurred fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { self.0.source() } } @@ -398,7 +398,7 @@ impl ParseError { } } - // To be consistent with `write_err` we need to **not** return source in case of overflow + // To be consistent with `write_err` we need to **not** return source if overflow occurred #[cfg(feature = "std")] fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { use core::num::IntErrorKind;