From 290e4418e68f4978b44e46f174f0a0243122278b Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 13 Mar 2024 09:34:58 +1100 Subject: [PATCH] units: Fix cargo cult programming 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. --- bitcoin/src/parse.rs | 0 units/src/parse.rs | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 bitcoin/src/parse.rs diff --git a/bitcoin/src/parse.rs b/bitcoin/src/parse.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/units/src/parse.rs b/units/src/parse.rs index ba0b4b2c..76d78cf9 100644 --- a/units/src/parse.rs +++ b/units/src/parse.rs @@ -108,8 +108,8 @@ pub(crate) fn strip_hex_prefix(s: &str) -> &str { pub fn hex_u32 + Into>(s: S) -> Result { u32::from_str_radix(strip_hex_prefix(s.as_ref()), 16).map_err(|error| ParseIntError { input: s.into(), - bits: u8::try_from(core::mem::size_of::() * 8).expect("max is 32 bits for u32"), - is_signed: u32::try_from(-1i8).is_ok(), + bits: 32, + is_signed: false, source: error, }) }