units: Use functional style
This is Rust not C, use functional style. Close: #4464
This commit is contained in:
parent
e43c574146
commit
f732b1d3cc
|
@ -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
|
/// 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.
|
/// [`BlockHeightInterval`] is a thin wrapper around a `u32`, the two types are not interchangeable.
|
||||||
fn try_from(h: BlockHeightInterval) -> Result<Self, Self::Error> {
|
fn try_from(h: BlockHeightInterval) -> Result<Self, Self::Error> {
|
||||||
let h = h.to_u32();
|
u16::try_from(h.to_u32())
|
||||||
|
.map(relative::NumberOfBlocks::from)
|
||||||
if h > u32::from(u16::MAX) {
|
.map_err(|_| TooBigForRelativeHeightError(h.into()))
|
||||||
return Err(TooBigForRelativeHeightError(h));
|
|
||||||
}
|
|
||||||
Ok(relative::NumberOfBlocks::from(h as u16)) // Cast ok, value checked above.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue