From 77d473e22c0a9587e98016093b375d4843b0786f Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 12 May 2024 02:47:40 +0200 Subject: [PATCH] refactor: split-numbers generic by converting to u128 #76 --- members/libpt-bintols/src/split_numbers.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/members/libpt-bintols/src/split_numbers.rs b/members/libpt-bintols/src/split_numbers.rs index 84a29cb..20cefa6 100644 --- a/members/libpt-bintols/src/split_numbers.rs +++ b/members/libpt-bintols/src/split_numbers.rs @@ -3,25 +3,20 @@ //! Sometimes, you need a large integer in the form of many bytes, so split into [u8]. //! Rust provides -use num_traits::Unsigned; - /// split an integer into it's bytes, ignoring those bytes that would be all zero. /// /// If the integer is zero, the Vec contains a single null byte. -pub fn unsigned_to_vec(mut num: T) -> Vec +pub fn unsigned_to_vec(num: T) -> Vec where - T: Unsigned, - T: std::ops::ShrAssign, - T: std::cmp::PartialOrd, - u8: std::convert::From, - T: Copy, + u128: std::convert::From { + let mut num: u128 = num.into(); if num == 0 { return vec![0]; } let mut buf: Vec = Vec::new(); while num > 0 { - buf.push(num.into()); + buf.push(num as u8); num >>= 8; } buf