fix: use a dependency to split the int instead of a builtin function
cargo devel CI / cargo CI (push) Has been cancelled Details

This commit is contained in:
Christoph J. Scherr 2024-05-12 18:36:36 +02:00
parent 66144dcb3c
commit e1be745a2f
2 changed files with 5 additions and 14 deletions

View File

@ -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"]}

View File

@ -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<u8> {
if num == 0 {
return vec![0];
}
let mut buf: Vec<u8> = Vec::new();
while num > 0 {
buf.push(num as u8);
num >>= 8;
}
buf
}