Skip to content

Commit

Permalink
fix OwnedBytes debug panic (#2512)
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh authored Oct 16, 2024
1 parent c17e513 commit 6dfa2df
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ownedbytes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl fmt::Debug for OwnedBytes {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// We truncate the bytes in order to make sure the debug string
// is not too long.
let bytes_truncated: &[u8] = if self.len() > 8 {
let bytes_truncated: &[u8] = if self.len() > 10 {
&self.as_slice()[..10]
} else {
self.as_slice()
Expand Down Expand Up @@ -252,6 +252,11 @@ mod tests {
format!("{short_bytes:?}"),
"OwnedBytes([97, 98, 99, 100], len=4)"
);
let medium_bytes = OwnedBytes::new(b"abcdefghi".as_ref());
assert_eq!(
format!("{medium_bytes:?}"),
"OwnedBytes([97, 98, 99, 100, 101, 102, 103, 104, 105], len=9)"
);
let long_bytes = OwnedBytes::new(b"abcdefghijklmnopq".as_ref());
assert_eq!(
format!("{long_bytes:?}"),
Expand Down

0 comments on commit 6dfa2df

Please sign in to comment.