Better debug formatting for StaticVec.

This commit is contained in:
Stephen Chung 2020-06-11 22:18:30 +08:00
parent 8f55a15ab0
commit e4cca7620f
4 changed files with 18 additions and 20 deletions

View File

@ -202,17 +202,17 @@ impl fmt::Display for Dynamic {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.0 {
Union::Unit(_) => write!(f, ""),
Union::Bool(value) => write!(f, "{}", value),
Union::Str(value) => write!(f, "{}", value),
Union::Char(value) => write!(f, "{}", value),
Union::Int(value) => write!(f, "{}", value),
Union::Bool(value) => fmt::Display::fmt(value, f),
Union::Str(value) => fmt::Display::fmt(value, f),
Union::Char(value) => fmt::Display::fmt(value, f),
Union::Int(value) => fmt::Display::fmt(value, f),
#[cfg(not(feature = "no_float"))]
Union::Float(value) => write!(f, "{}", value),
Union::Float(value) => fmt::Display::fmt(value, f),
#[cfg(not(feature = "no_index"))]
Union::Array(value) => write!(f, "{:?}", value),
Union::Array(value) => fmt::Debug::fmt(value, f),
#[cfg(not(feature = "no_object"))]
Union::Map(value) => write!(f, "#{:?}", value),
Union::Module(value) => write!(f, "{:?}", value),
Union::Module(value) => fmt::Debug::fmt(value, f),
#[cfg(not(feature = "no_std"))]
Union::Variant(value) if value.is::<Instant>() => write!(f, "<timestamp>"),
@ -224,18 +224,18 @@ impl fmt::Display for Dynamic {
impl fmt::Debug for Dynamic {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.0 {
Union::Unit(value) => write!(f, "{:?}", value),
Union::Bool(value) => write!(f, "{:?}", value),
Union::Str(value) => write!(f, "{:?}", value),
Union::Char(value) => write!(f, "{:?}", value),
Union::Int(value) => write!(f, "{:?}", value),
Union::Unit(value) => fmt::Debug::fmt(value, f),
Union::Bool(value) => fmt::Debug::fmt(value, f),
Union::Str(value) => fmt::Debug::fmt(value, f),
Union::Char(value) => fmt::Debug::fmt(value, f),
Union::Int(value) => fmt::Debug::fmt(value, f),
#[cfg(not(feature = "no_float"))]
Union::Float(value) => write!(f, "{:?}", value),
Union::Float(value) => fmt::Debug::fmt(value, f),
#[cfg(not(feature = "no_index"))]
Union::Array(value) => write!(f, "{:?}", value),
Union::Array(value) => fmt::Debug::fmt(value, f),
#[cfg(not(feature = "no_object"))]
Union::Map(value) => write!(f, "#{:?}", value),
Union::Module(value) => write!(f, "{:?}", value),
Union::Module(value) => fmt::Debug::fmt(value, f),
#[cfg(not(feature = "no_std"))]
Union::Variant(value) if value.is::<Instant>() => write!(f, "<timestamp>"),

View File

@ -82,7 +82,7 @@ impl fmt::Debug for CallableFunction {
Self::Pure(_) => write!(f, "NativePureFunction"),
Self::Method(_) => write!(f, "NativeMethod"),
Self::Iterator(_) => write!(f, "NativeIterator"),
Self::Script(fn_def) => write!(f, "{:?}", fn_def),
Self::Script(fn_def) => fmt::Debug::fmt(fn_def, f),
}
}
}

View File

@ -65,7 +65,7 @@ impl fmt::Debug for Module {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"<module {:?}, functions={}>",
"<module vars={:?}, functions={}>",
self.variables,
self.functions.len(),
)

View File

@ -542,9 +542,7 @@ impl<T: Default> StaticVec<T> {
impl<T: fmt::Debug> fmt::Debug for StaticVec<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[ ")?;
self.iter().try_for_each(|v| write!(f, "{:?}, ", v))?;
write!(f, "]")
fmt::Debug::fmt(&self.iter().collect::<Vec<_>>(), f)
}
}