Skip to content

Commit

Permalink
fix(aya-log): print &[u8] using full width
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigorenkoPV authored and alessandrod committed Sep 1, 2024
1 parent ab5e688 commit e2bfbab
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions aya-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,22 @@ trait Format {

impl Format for &[u8] {
fn format(&self, last_hint: Option<DisplayHintWrapper>) -> Result<String, ()> {
use core::fmt::Write;
match last_hint.map(|DisplayHintWrapper(dh)| dh) {
Some(DisplayHint::LowerHex) => Ok(LowerHexDebugFormatter::format(self)),
Some(DisplayHint::UpperHex) => Ok(UpperHexDebugFormatter::format(self)),
Some(DisplayHint::LowerHex) => {
let mut s = String::new();
for &byte in *self {
write!(&mut s, "{byte:02x}").unwrap();
}
Ok(s)
}
Some(DisplayHint::UpperHex) => {
let mut s = String::new();
for &byte in *self {
write!(&mut s, "{byte:02X}").unwrap();
}
Ok(s)
}
_ => Err(()),
}
}
Expand Down

0 comments on commit e2bfbab

Please sign in to comment.