Skip to content

Commit 029d5c6

Browse files
committed
units: Add Errors section to rustdocs
In `units` we lint for the `# Errors` section but in `primitives` we don't so during recent code move from `primitives` to `units` we introduced a bunch of lint warnings. Add docs and clear all lint warnings.
1 parent fa0c968 commit 029d5c6

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

units/src/locktime/absolute/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ impl LockTime {
112112

113113
/// Constructs a new `LockTime` from a prefixed hex string.
114114
///
115+
/// # Errors
116+
///
117+
/// If the input string is not a valid hex representation of a locktime or it does not include
118+
/// the `0x` prefix.
119+
///
115120
/// # Examples
116121
///
117122
/// ```
@@ -130,6 +135,11 @@ impl LockTime {
130135

131136
/// Constructs a new `LockTime` from an unprefixed hex string.
132137
///
138+
/// # Errors
139+
///
140+
/// If the input string is not a valid hex representation of a locktime or if it includes the
141+
/// `0x` prefix.
142+
///
133143
/// # Examples
134144
///
135145
/// ```
@@ -177,6 +187,11 @@ impl LockTime {
177187
///
178188
/// See [`LOCK_TIME_THRESHOLD`] for definition of a valid height value.
179189
///
190+
/// # Errors
191+
///
192+
/// If `n` does not represent a block height within the valid range for a locktime:
193+
/// `[0, 499_999_999]`.
194+
///
180195
/// # Examples
181196
///
182197
/// ```rust
@@ -209,6 +224,10 @@ impl LockTime {
209224
///
210225
/// See [`LOCK_TIME_THRESHOLD`] for definition of a valid time value.
211226
///
227+
/// # Errors
228+
///
229+
/// If `n` is not in the allowable range of MTPs in a locktime: `[500_000_000, 2^32 - 1]`.
230+
///
212231
/// # Examples
213232
///
214233
/// ```rust

units/src/locktime/relative/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ impl LockTime {
6161
/// locktimes only use some bits of the underlying `u32` value and discard the rest. If
6262
/// you want to preserve the full value, you should use the [`Sequence`] type instead.
6363
///
64+
/// # Errors
65+
///
66+
/// If `n`, interpreted as a [`Sequence`] number does not encode a relative lock time.
67+
///
6468
/// # Examples
6569
///
6670
/// ```rust
@@ -106,6 +110,11 @@ impl LockTime {
106110
///
107111
/// This method will **not** round-trip with [`Self::to_sequence`]. See the
108112
/// docs for [`Self::from_consensus`] for more information.
113+
///
114+
/// # Errors
115+
///
116+
/// If `n` does not encode a relative lock time.
117+
///
109118
/// # Examples
110119
///
111120
/// ```rust

units/src/sequence.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,23 @@ impl Sequence {
122122
}
123123

124124
/// Constructs a new `Sequence` from a prefixed hex string.
125+
///
126+
/// # Errors
127+
///
128+
/// If the input string is not a valid hex representation of a locktime or it does not include
129+
/// the `0x` prefix.
125130
#[inline]
126131
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
127132
let lock_time = parse::hex_u32_prefixed(s)?;
128133
Ok(Self::from_consensus(lock_time))
129134
}
130135

131136
/// Constructs a new `Sequence` from an unprefixed hex string.
137+
///
138+
/// # Errors
139+
///
140+
/// If the input string is not a valid hex representation of a locktime or if it includes the
141+
/// `0x` prefix.
132142
#[inline]
133143
pub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError> {
134144
let lock_time = parse::hex_u32_unprefixed(s)?;
@@ -152,6 +162,11 @@ impl Sequence {
152162
/// interval with floor division.
153163
///
154164
/// Will return an error if the input cannot be encoded in 16 bits.
165+
///
166+
/// # Errors
167+
///
168+
/// Will return an error if `seconds` cannot be encoded in 16 bits. See
169+
/// [`NumberOf512Seconds::from_seconds_floor`].
155170
#[inline]
156171
pub fn from_seconds_floor(seconds: u32) -> Result<Self, TimeOverflowError> {
157172
let intervals = NumberOf512Seconds::from_seconds_floor(seconds)?;
@@ -162,6 +177,11 @@ impl Sequence {
162177
/// interval with ceiling division.
163178
///
164179
/// Will return an error if the input cannot be encoded in 16 bits.
180+
///
181+
/// # Errors
182+
///
183+
/// Will return an error if `seconds` cannot be encoded in 16 bits. See
184+
/// [`NumberOf512Seconds::from_seconds_ceil`].
165185
#[inline]
166186
pub fn from_seconds_ceil(seconds: u32) -> Result<Self, TimeOverflowError> {
167187
let intervals = NumberOf512Seconds::from_seconds_ceil(seconds)?;

0 commit comments

Comments
 (0)