Merge rust-bitcoin/rust-bitcoin#4467: units: Use functional style

f732b1d3cc units: Use functional style (Tobin C. Harding)

Pull request description:

  This is Rust not C, use functional style.

  Close: #4464

ACKs for top commit:
  apoelstra:
    ACK f732b1d3cc2b3f9d012b3eeecc70d007666d4f1d; successfully ran local tests

Tree-SHA512: 65f523d4632c78bb166b9e4fb49e715e92da28fc2d07d54a3df8e0db7097277958dfbde0989cf1e443e6f56635001298b47fef3eb5e76b8350041b1ee7be46a6
This commit is contained in:
merge-script 2025-05-12 11:53:39 +00:00
commit 76e9a3e433
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 3 additions and 6 deletions

View File

@ -158,12 +158,9 @@ impl TryFrom<BlockHeightInterval> for relative::NumberOfBlocks {
/// A relative locktime block height has a maximum value of `u16::MAX` where as a
/// [`BlockHeightInterval`] is a thin wrapper around a `u32`, the two types are not interchangeable.
fn try_from(h: BlockHeightInterval) -> Result<Self, Self::Error> {
let h = h.to_u32();
if h > u32::from(u16::MAX) {
return Err(TooBigForRelativeHeightError(h));
}
Ok(relative::NumberOfBlocks::from(h as u16)) // Cast ok, value checked above.
u16::try_from(h.to_u32())
.map(relative::NumberOfBlocks::from)
.map_err(|_| TooBigForRelativeHeightError(h.into()))
}
}