initial
This commit is contained in:
26
src/debug.rs
Normal file
26
src/debug.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
#[cfg(feature = "debug-trace")]
|
||||
macro_rules! trace {
|
||||
($($arg:tt)*) => {
|
||||
eprintln!("[TRACE] {}", format!($($arg)*));
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "debug-trace"))]
|
||||
macro_rules! trace {
|
||||
($($arg:tt)*) => {};
|
||||
}
|
||||
|
||||
pub(crate) use trace;
|
||||
|
||||
pub fn hex_preview(data: &[u8], len: usize) -> String {
|
||||
let preview: Vec<String> = data
|
||||
.iter()
|
||||
.take(len)
|
||||
.map(|b| format!("{:02x}", b))
|
||||
.collect();
|
||||
if data.len() > len {
|
||||
format!("{}... ({} bytes)", preview.join(""), data.len())
|
||||
} else {
|
||||
preview.join("")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user