diff --git a/crates/bevy_utils/src/debug_info.rs b/crates/bevy_utils/src/debug_info.rs index 3aad20dfc2ed5..5f1f1aefd4391 100644 --- a/crates/bevy_utils/src/debug_info.rs +++ b/crates/bevy_utils/src/debug_info.rs @@ -14,7 +14,7 @@ const FEATURE_DISABLED: &str = "Enable the debug feature to see the name"; /// /// * If the `debug` feature is enabled, the actual name will be used /// * If it is disabled, a string mentioning the disabled feature will be used -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] pub struct DebugName { #[cfg(feature = "debug")] name: Cow<'static, str>, @@ -23,12 +23,15 @@ pub struct DebugName { cfg::alloc! { impl fmt::Display for DebugName { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - #[cfg(feature = "debug")] - f.write_str(self.name.as_ref())?; - #[cfg(not(feature = "debug"))] - f.write_str(FEATURE_DISABLED)?; + // Deref to `str`, which will use `FEATURE_DISABLED` if necessary + write!(f, "{}", &**self) + } + } - Ok(()) + impl fmt::Debug for DebugName { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + // Deref to `str`, which will use `FEATURE_DISABLED` if necessary + write!(f, "{:?}", &**self) } } }