Use uniform docs for overflow
Trivial change but make all the docs (rustdocs and code comments) use the same phrase when describing overflow.
This commit is contained in:
parent
153a6a2f3c
commit
7fbe07a6e0
|
@ -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<BlockHeightInterval> {
|
||||
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> {
|
||||
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> { 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> { 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<BlockMtpInterval> {
|
||||
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> {
|
||||
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> { 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> { self.0.checked_add(other.0).map(Self) }
|
||||
}
|
||||
|
|
|
@ -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<Self> {
|
||||
// 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<Self> {
|
||||
// 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<Self> {
|
||||
// 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<Self> {
|
||||
// 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<Self> {
|
||||
// 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<Self> {
|
||||
// No `map()` in const context.
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue