use std::fmt::Write;
pub(super) fn colon_string(bytes: &[u8]) -> String {
let cap = bytes.len() * 2; let cap = cap + (cap / 2) - 1; let mut s = String::with_capacity(cap);
for v in &bytes[..bytes.len() - 1] {
write!(&mut s, "{v:02x}:").expect("infallible append");
}
write!(&mut s, "{:02x}", bytes.last().unwrap()).expect("infallible append");
s
}
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;
#[test]
fn test_fixture() {
let hex_str = colon_string(&[42, 13, 00, 0xCA, 0xFE]);
assert_eq!(hex_str, "2a:0d:00:ca:fe");
}
proptest! {
#[test]
fn prop_render(
value in prop::collection::vec(any::<u8>(), 1..129), ) {
let hex_str = colon_string(&value);
let raw = hex::decode(hex_str.replace(':', "")).expect("valid hex");
assert_eq!(raw, value);
}
}
}