Reimplement fmt::Debug for Bytes and BytesMut (#84)

Standard `Debug` implementation for `[u8]` is comma separated list
of numbers. Since large amount of byte strings are in fact ASCII
strings or contain a lot of ASCII strings (e. g. HTTP), it is
convenient to print strings as ASCII when possible.
This commit is contained in:
Stepan Koltsov
2017-03-20 21:09:44 -07:00
committed by Carl Lerche
parent dc9c8e304e
commit 613d4bd5d5
5 changed files with 80 additions and 3 deletions
+3 -2
View File
@@ -1,5 +1,6 @@
use {IntoBuf, Buf, BufMut};
use buf::Iter;
use debug;
use std::{cmp, fmt, mem, hash, ops, slice, ptr, usize};
use std::borrow::Borrow;
@@ -722,7 +723,7 @@ impl Eq for Bytes {
impl fmt::Debug for Bytes {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.inner.as_ref(), fmt)
fmt::Debug::fmt(&debug::BsDebug(&self.inner.as_ref()), fmt)
}
}
@@ -1260,7 +1261,7 @@ impl Eq for BytesMut {
impl fmt::Debug for BytesMut {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self.inner.as_ref(), fmt)
fmt::Debug::fmt(&debug::BsDebug(&self.inner.as_ref()), fmt)
}
}