Merge rust-bitcoin/rust-bitcoin#2577: Fix cargo cult programming
290e4418e6
units: Fix cargo cult programming (Tobin C. Harding) Pull request description: When creating the ParseIntError in `hex_u32` I (tobin) just cargo cult programmed the generic stuff without thinking. - The `is_signed` field is used to denote whether we were attempting to parse a signed or unsigned integer, it should be `false`. - The `bits` field should be directly set to 32. ACKs for top commit: apoelstra: ACK290e4418e6
sanket1729: ACK290e4418e6
Tree-SHA512: 7dfd9f0cd98eff1c2b27a92dac5c4e2fe0fa4ae724528ef741fe43d8d923e2d31cbdcd4e540ecfba1b953860dc2b728a958e756e2d2012d9a9e715c0ca3c5068
This commit is contained in:
commit
6389d3f7fc
|
@ -108,8 +108,8 @@ pub(crate) fn strip_hex_prefix(s: &str) -> &str {
|
||||||
pub fn hex_u32<S: AsRef<str> + Into<String>>(s: S) -> Result<u32, ParseIntError> {
|
pub fn hex_u32<S: AsRef<str> + Into<String>>(s: S) -> Result<u32, ParseIntError> {
|
||||||
u32::from_str_radix(strip_hex_prefix(s.as_ref()), 16).map_err(|error| ParseIntError {
|
u32::from_str_radix(strip_hex_prefix(s.as_ref()), 16).map_err(|error| ParseIntError {
|
||||||
input: s.into(),
|
input: s.into(),
|
||||||
bits: u8::try_from(core::mem::size_of::<u32>() * 8).expect("max is 32 bits for u32"),
|
bits: 32,
|
||||||
is_signed: u32::try_from(-1i8).is_ok(),
|
is_signed: false,
|
||||||
source: error,
|
source: error,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue