Skip to content

Commit 732a83c

Browse files
committed
Merge rust-bitcoin#4629: Improve locktime docs
70221ff Fix link to use new name (Tobin C. Harding) ebf92fc Use ASCII in rusdocs (Tobin C. Harding) 64ece63 Add missing whitespace character to rustdoc (Tobin C. Harding) 64e1068 Improve rustdoc examples for absolute locktime (Tobin C. Harding) Pull request description: In preparation for release go over the locktime rustdocs. Close: rust-bitcoin#4463 ACKs for top commit: jamillambert: ACK 70221ff apoelstra: ACK 70221ff; successfully ran local tests Tree-SHA512: 67bc51400056e08018f92f8e7ff91c8f8db9e6b575e83f8937a382bde45541a31e75277e200694180fa5098b681e200858fb7b0c9330065af0019955ed126a61
2 parents 7bbb908 + 70221ff commit 732a83c

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

units/src/locktime/absolute.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ impl Height {
6565
/// # Examples
6666
///
6767
/// ```rust
68-
/// use bitcoin_units::locktime::absolute::Height;
68+
/// use bitcoin_units::locktime::absolute;
6969
///
7070
/// let h: u32 = 741521;
71-
/// let height = Height::from_u32(h).expect("invalid height value");
72-
/// assert_eq!(height.to_consensus_u32(), h);
71+
/// let height = absolute::Height::from_u32(h)?;
72+
/// assert_eq!(height.to_u32(), h);
73+
/// # Ok::<_, absolute::ConversionError>(())
7374
/// ```
7475
#[inline]
7576
pub const fn from_u32(n: u32) -> Result<Height, ConversionError> {
@@ -81,6 +82,14 @@ impl Height {
8182
}
8283

8384
/// Converts this [`Height`] to a raw `u32` value.
85+
///
86+
/// # Examples
87+
///
88+
/// ```rust
89+
/// use bitcoin_units::locktime::absolute;
90+
///
91+
/// assert_eq!(absolute::Height::MAX.to_u32(), 499_999_999);
92+
/// ```
8493
#[inline]
8594
pub const fn to_u32(self) -> u32 { self.0 }
8695

@@ -144,7 +153,8 @@ impl MedianTimePast {
144153
/// The maximum MTP allowable in a locktime (Sun Feb 07 2106 06:28:15 GMT+0000).
145154
pub const MAX: Self = MedianTimePast(u32::MAX);
146155

147-
/// Constructs an [`MedianTimePast`] by computing the median‐time‐past from the last 11 block timestamps
156+
/// Constructs an [`MedianTimePast`] by computing the median-time-past from the last
157+
/// 11 block timestamps.
148158
///
149159
/// Because block timestamps are not monotonic, this function internally sorts them;
150160
/// it is therefore not important what order they appear in the array; use whatever
@@ -189,11 +199,12 @@ impl MedianTimePast {
189199
/// # Examples
190200
///
191201
/// ```rust
192-
/// use bitcoin_units::locktime::absolute::MedianTimePast;
202+
/// use bitcoin_units::locktime::absolute;
193203
///
194204
/// let t: u32 = 1653195600; // May 22nd, 5am UTC.
195-
/// let time = MedianTimePast::from_u32(t).expect("invalid time value");
196-
/// assert_eq!(time.to_consensus_u32(), t);
205+
/// let time = absolute::MedianTimePast::from_u32(t)?;
206+
/// assert_eq!(time.to_u32(), t);
207+
/// # Ok::<_, absolute::ConversionError>(())
197208
/// ```
198209
#[inline]
199210
pub const fn from_u32(n: u32) -> Result<Self, ConversionError> {
@@ -205,12 +216,20 @@ impl MedianTimePast {
205216
}
206217

207218
/// Converts this [`MedianTimePast`] to a raw `u32` value.
219+
///
220+
/// # Examples
221+
///
222+
/// ```rust
223+
/// use bitcoin_units::locktime::absolute;
224+
///
225+
/// assert_eq!(absolute::MedianTimePast::MIN.to_u32(), 500_000_000);
226+
/// ```
208227
#[inline]
209228
pub const fn to_u32(self) -> u32 { self.0 }
210229

211230
/// Returns true if a transaction with this locktime can be included in the next block.
212231
///
213-
/// `self`is the value of the `LockTime` and if `time` is the median time past of the block at
232+
/// `self` is the value of the `LockTime` and if `time` is the median time past of the block at
214233
/// the chain tip then a transaction with this lock can be broadcast for inclusion in the next
215234
/// block.
216235
#[inline]

units/src/locktime/relative.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl NumberOfBlocks {
3030
#[inline]
3131
pub const fn from_height(blocks: u16) -> Self { Self(blocks) }
3232

33-
/// Express the [`Height`] as a count of blocks.
33+
/// Express the [`NumberOfBlocks`] as a count of blocks.
3434
#[inline]
3535
#[must_use]
3636
pub const fn to_height(self) -> u16 { self.0 }

0 commit comments

Comments
 (0)