Skip to content

Commit

Permalink
Simplify debug printing
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jun 19, 2024
1 parent fa56c3d commit 9d3e7d7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,7 @@ impl<const N: usize> Debug for Bytes<N> {
use core::ascii::escape_default;
f.write_str("b'")?;
for byte in &self.bytes {
for ch in escape_default(*byte) {
// Debug::fmt(unsafe { core::str::from_utf8_unchecked(&[ch]) }, f)?;
f.write_str(unsafe { core::str::from_utf8_unchecked(&[ch]) })?;
// f.write(&ch);
}
write!(f, "{}", escape_default(*byte))?;
}
f.write_str("'")?;
Ok(())
Expand Down Expand Up @@ -395,7 +391,7 @@ mod tests_serde {
use serde_test::{assert_tokens, Token};

#[test]
fn all() {
fn serde() {
let mut bytes = Bytes::<0>::new();
assert!(bytes.push(1).is_err());
assert_tokens(&bytes, &[Token::Bytes(&[])]);
Expand All @@ -414,6 +410,14 @@ mod tests_serde {
])],
);
}

#[test]
fn display() {
assert_eq!(
r"b'\x00abcde\n'",
format!("{:?}", Bytes::<10>::from_slice(b"\0abcde\n").unwrap())
);
}
}

#[cfg(test)]
Expand Down

0 comments on commit 9d3e7d7

Please sign in to comment.