From 7928423d6e2c4c6bbc5ac2320d80d0dc87a05c3d Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Mon, 13 May 2024 15:13:35 +0200 Subject: [PATCH] refactor(bintols-join): return err if the result cannot be converted to T #80 #79 --- members/libpt-bintols/src/join.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/members/libpt-bintols/src/join.rs b/members/libpt-bintols/src/join.rs index 35efcd7..96c8e6e 100644 --- a/members/libpt-bintols/src/join.rs +++ b/members/libpt-bintols/src/join.rs @@ -27,7 +27,13 @@ pub fn array_to_unsigned(parts: &[u8]) -> anyhow::Result where u128: std::convert::From, T: std::str::FromStr, + T: std::convert::TryFrom, ::Err: std::fmt::Debug, + ::Err: std::error::Error, + >::Error: std::error::Error, + >::Error: std::marker::Send, + >::Error: std::marker::Sync, + >::Error: 'static, { trace!("amount of parts: {}", parts.len()); if parts.len() > (u128::BITS / 8) as usize { @@ -40,5 +46,5 @@ where for (i, e) in parts.iter().rev().enumerate() { ri += (*e as u128) * 256u128.pow(i as u32); } - Ok(ri.to_string().parse().unwrap()) + T::try_from(ri).map_err(anyhow::Error::from) }