From e1be745a2fb395253821a2f870cd87ec588e194c Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 12 May 2024 18:36:36 +0200 Subject: [PATCH] fix: use a dependency to split the int instead of a builtin function --- Cargo.toml | 1 + src/format.rs | 18 ++++-------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 44f64bf..4598dd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,5 @@ anyhow = "1.0.83" clap = { version = "4.5.4", features = ["derive"] } clap-num = "1.1.1" fast32 = "1.0.2" +libpt = { version = "0.5.0", features = ["bintols"]} diff --git a/src/format.rs b/src/format.rs index 4aaca53..fe425df 100644 --- a/src/format.rs +++ b/src/format.rs @@ -1,3 +1,5 @@ +use libpt::bintols::split; + pub type Num = u128; #[derive(Copy, Clone, Debug)] @@ -47,21 +49,9 @@ impl Format { Format::Dec => { buf += &format!("{num}"); } - Format::Base64 => buf += &fast32::base64::RFC4648.encode(&u128_to_u8_slice(num)), - Format::Base32 => buf += &fast32::base32::RFC4648.encode(&u128_to_u8_slice(num)), + Format::Base64 => buf += &fast32::base64::RFC4648.encode(&split::unsigned_to_vec(num)), + Format::Base32 => buf += &fast32::base32::RFC4648.encode(&split::unsigned_to_vec(num)), } buf } } - -fn u128_to_u8_slice(mut num: u128) -> Vec { - if num == 0 { - return vec![0]; - } - let mut buf: Vec = Vec::new(); - while num > 0 { - buf.push(num as u8); - num >>= 8; - } - buf -}