Skip to content

Commit 7fbe07a

Browse files
committed
Use uniform docs for overflow
Trivial change but make all the docs (rustdocs and code comments) use the same phrase when describing overflow.
1 parent 153a6a2 commit 7fbe07a

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

units/src/block.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ impl BlockHeight {
8787
/// Returns block height as a `u32`.
8888
pub const fn to_u32(self) -> u32 { self.0 }
8989

90-
/// Attempt to subtract two [`BlockHeight`]s, returning `None` in case of overflow.
90+
/// Attempt to subtract two [`BlockHeight`]s, returning `None` if overflow occurred.
9191
#[must_use]
9292
pub fn checked_sub(self, other: Self) -> Option<BlockHeightInterval> {
9393
self.0.checked_sub(other.0).map(BlockHeightInterval)
9494
}
9595

96-
/// Attempt to add an interval to this [`BlockHeight`], returning `None` in case of overflow.
96+
/// Attempt to add an interval to this [`BlockHeight`], returning `None` if overflow occurred.
9797
#[must_use]
9898
pub fn checked_add(self, other: BlockHeightInterval) -> Option<Self> {
9999
self.0.checked_add(other.0).map(Self)
@@ -148,11 +148,11 @@ impl BlockHeightInterval {
148148
/// Returns block interval as a `u32`.
149149
pub const fn to_u32(self) -> u32 { self.0 }
150150

151-
/// Attempt to subtract two [`BlockHeightInterval`]s, returning `None` in case of overflow.
151+
/// Attempt to subtract two [`BlockHeightInterval`]s, returning `None` if overflow occurred.
152152
#[must_use]
153153
pub fn checked_sub(self, other: Self) -> Option<Self> { self.0.checked_sub(other.0).map(Self) }
154154

155-
/// Attempt to add two [`BlockHeightInterval`]s, returning `None` in case of overflow.
155+
/// Attempt to add two [`BlockHeightInterval`]s, returning `None` if overflow occurred.
156156
#[must_use]
157157
pub fn checked_add(self, other: Self) -> Option<Self> { self.0.checked_add(other.0).map(Self) }
158158
}
@@ -220,13 +220,13 @@ impl BlockMtp {
220220
Self::from_u32(u32::from(timestamps[5]))
221221
}
222222

223-
/// Attempt to subtract two [`BlockMtp`]s, returning `None` in case of overflow.
223+
/// Attempt to subtract two [`BlockMtp`]s, returning `None` if overflow occurred.
224224
#[must_use]
225225
pub fn checked_sub(self, other: Self) -> Option<BlockMtpInterval> {
226226
self.0.checked_sub(other.0).map(BlockMtpInterval)
227227
}
228228

229-
/// Attempt to add an interval to this [`BlockMtp`], returning `None` in case of overflow.
229+
/// Attempt to add an interval to this [`BlockMtp`], returning `None` if overflow occurred.
230230
#[must_use]
231231
pub fn checked_add(self, other: BlockMtpInterval) -> Option<Self> {
232232
self.0.checked_add(other.0).map(Self)
@@ -313,11 +313,11 @@ impl BlockMtpInterval {
313313
relative::NumberOf512Seconds::from_seconds_ceil(self.to_u32())
314314
}
315315

316-
/// Attempt to subtract two [`BlockMtpInterval`]s, returning `None` in case of overflow.
316+
/// Attempt to subtract two [`BlockMtpInterval`]s, returning `None` if overflow occurred.
317317
#[must_use]
318318
pub fn checked_sub(self, other: Self) -> Option<Self> { self.0.checked_sub(other.0).map(Self) }
319319

320-
/// Attempt to add two [`BlockMtpInterval`]s, returning `None` in case of overflow.
320+
/// Attempt to add two [`BlockMtpInterval`]s, returning `None` if overflow occurred.
321321
#[must_use]
322322
pub fn checked_add(self, other: Self) -> Option<Self> { self.0.checked_add(other.0).map(Self) }
323323
}

units/src/fee_rate/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ impl FeeRate {
5252
/// The fee rate used to compute dust amount.
5353
pub const DUST: FeeRate = FeeRate::from_sat_per_vb_u32(3);
5454

55-
/// Constructs a new [`FeeRate`] from satoshis per 1000 weight units.
55+
/// Constructs a new [`FeeRate`] from satoshis per 1000 weight units,
56+
/// returning `None` if overflow occurred.
5657
pub const fn from_sat_per_kwu(sat_kwu: u64) -> Option<Self> {
5758
// No `map()` in const context.
5859
match sat_kwu.checked_mul(4_000) {
@@ -61,11 +62,8 @@ impl FeeRate {
6162
}
6263
}
6364

64-
/// Constructs a new [`FeeRate`] from satoshis per virtual bytes.
65-
///
66-
/// # Errors
67-
///
68-
/// Returns [`None`] on arithmetic overflow.
65+
/// Constructs a new [`FeeRate`] from satoshis per virtual bytes,
66+
/// returning `None` if overflow occurred.
6967
pub const fn from_sat_per_vb(sat_vb: u64) -> Option<Self> {
7068
// No `map()` in const context.
7169
match sat_vb.checked_mul(1_000_000) {
@@ -80,7 +78,8 @@ impl FeeRate {
8078
FeeRate::from_sat_per_mvb(sat_vb * 1_000_000)
8179
}
8280

83-
/// Constructs a new [`FeeRate`] from satoshis per kilo virtual bytes (1,000 vbytes).
81+
/// Constructs a new [`FeeRate`] from satoshis per kilo virtual bytes (1,000 vbytes),
82+
/// returning `None` if overflow occurred.
8483
pub const fn from_sat_per_kvb(sat_kvb: u64) -> Option<Self> {
8584
// No `map()` in const context.
8685
match sat_kvb.checked_mul(1_000) {
@@ -109,7 +108,7 @@ impl FeeRate {
109108

110109
/// Checked multiplication.
111110
///
112-
/// Computes `self * rhs` returning [`None`] if overflow occurred.
111+
/// Computes `self * rhs`, returning [`None`] if overflow occurred.
113112
#[must_use]
114113
pub const fn checked_mul(self, rhs: u64) -> Option<Self> {
115114
// No `map()` in const context.
@@ -133,7 +132,7 @@ impl FeeRate {
133132

134133
/// Checked addition.
135134
///
136-
/// Computes `self + rhs` returning [`None`] if overflow occurred.
135+
/// Computes `self + rhs` returning [`None`] is case of overflow.
137136
#[must_use]
138137
pub const fn checked_add(self, rhs: FeeRate) -> Option<Self> {
139138
// No `map()` in const context.
@@ -145,7 +144,7 @@ impl FeeRate {
145144

146145
/// Checked subtraction.
147146
///
148-
/// Computes `self - rhs` returning [`None`] if overflow occurred.
147+
/// Computes `self - rhs`, returning [`None`] if overflow occurred.
149148
#[must_use]
150149
pub const fn checked_sub(self, rhs: FeeRate) -> Option<Self> {
151150
// No `map()` in const context.

units/src/locktime/absolute.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl fmt::Display for ParseHeightError {
114114

115115
#[cfg(feature = "std")]
116116
impl std::error::Error for ParseHeightError {
117-
// To be consistent with `write_err` we need to **not** return source in case of overflow
117+
// To be consistent with `write_err` we need to **not** return source if overflow occurred
118118
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { self.0.source() }
119119
}
120120

@@ -239,7 +239,7 @@ impl fmt::Display for ParseTimeError {
239239

240240
#[cfg(feature = "std")]
241241
impl std::error::Error for ParseTimeError {
242-
// To be consistent with `write_err` we need to **not** return source in case of overflow
242+
// To be consistent with `write_err` we need to **not** return source if overflow occurred
243243
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { self.0.source() }
244244
}
245245

@@ -398,7 +398,7 @@ impl ParseError {
398398
}
399399
}
400400

401-
// To be consistent with `write_err` we need to **not** return source in case of overflow
401+
// To be consistent with `write_err` we need to **not** return source if overflow occurred
402402
#[cfg(feature = "std")]
403403
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
404404
use core::num::IntErrorKind;

0 commit comments

Comments
 (0)