#![cfg(test)]
pub(crate) fn partial_hexlify(data: &[u8]) -> String {
data.iter()
.map(|b| {
if let 0x20..=0x7E = b {
char::from(*b).to_string()
} else {
format!("\\x{b:02X}")
}
})
.collect()
}
macro_rules! all_variant_mapping {
(
$enum_type:path => $expr_type:ty :
$(
$variant:path
= ( $( $constructor:expr ),* )
=> $value:expr,
)*
) => {
{
fn _ensure_exhaustive(example: $enum_type) {
match example {
$( $variant (..) => (), )*
}
}
let kvs: Vec<($enum_type, $expr_type)> = vec![
$( ($variant ( $( $constructor ),* ), $value) ),*
];
kvs
}
};
}
pub(crate) use all_variant_mapping;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hexlify() {
assert_eq!(
partial_hexlify(&[0x00, 0x19, 0x20, 0x38, 0x41, 0x61, 0x7E, 0x7F, 0x80, 0xFF]),
r"\x00\x19 8Aa~\x7F\x80\xFF"
);
}
}