Display type name when printing Dynamic values that have no built-in format.

This commit is contained in:
Stephen Chung 2020-07-21 20:58:53 +08:00
parent e8b6d0143d
commit ec3074106e

View File

@ -243,12 +243,15 @@ impl fmt::Display for Dynamic {
#[cfg(not(feature = "no_index"))]
Union::Array(value) => fmt::Debug::fmt(value, f),
#[cfg(not(feature = "no_object"))]
Union::Map(value) => write!(f, "#{:?}", value),
Union::Map(value) => {
f.write_str("#")?;
fmt::Debug::fmt(value, f)
}
Union::FnPtr(value) => fmt::Display::fmt(value, f),
#[cfg(not(feature = "no_std"))]
Union::Variant(value) if value.is::<Instant>() => write!(f, "<timestamp>"),
Union::Variant(_) => write!(f, "?"),
Union::Variant(value) => write!(f, "{}", (*value).type_name()),
}
}
}
@ -266,12 +269,15 @@ impl fmt::Debug for Dynamic {
#[cfg(not(feature = "no_index"))]
Union::Array(value) => fmt::Debug::fmt(value, f),
#[cfg(not(feature = "no_object"))]
Union::Map(value) => write!(f, "#{:?}", value),
Union::Map(value) => {
f.write_str("#")?;
fmt::Debug::fmt(value, f)
}
Union::FnPtr(value) => fmt::Display::fmt(value, f),
#[cfg(not(feature = "no_std"))]
Union::Variant(value) if value.is::<Instant>() => write!(f, "<timestamp>"),
Union::Variant(_) => write!(f, "<dynamic>"),
Union::Variant(value) => write!(f, "{}", (*value).type_name()),
}
}
}