From 97d8a6bafc3ee9d6951f2de02cff01110c97e9c1 Mon Sep 17 00:00:00 2001 From: Chris Russell <8494645+chescock@users.noreply.github.com> Date: Mon, 17 Nov 2025 09:47:52 -0500 Subject: [PATCH 1/2] Manually impl Debug for DebugName. --- crates/bevy_utils/src/debug_info.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/bevy_utils/src/debug_info.rs b/crates/bevy_utils/src/debug_info.rs index 3aad20dfc2ed5..bf1c7ebd324f9 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>, @@ -31,6 +31,17 @@ cfg::alloc! { Ok(()) } } + + impl fmt::Debug for DebugName { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + #[cfg(feature = "debug")] + write!(f, "{:?}", self.name.as_ref())?; + #[cfg(not(feature = "debug"))] + f.debug_struct("DebugName").finish()?; + + Ok(()) + } + } } impl DebugName { From 83ce3b19817c3ba10e4dd47e35b585babbbf5fb3 Mon Sep 17 00:00:00 2001 From: Chris Russell <8494645+chescock@users.noreply.github.com> Date: Mon, 17 Nov 2025 13:24:33 -0500 Subject: [PATCH 2/2] Have Debug and Display delegate to Deref. --- crates/bevy_utils/src/debug_info.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/bevy_utils/src/debug_info.rs b/crates/bevy_utils/src/debug_info.rs index bf1c7ebd324f9..5f1f1aefd4391 100644 --- a/crates/bevy_utils/src/debug_info.rs +++ b/crates/bevy_utils/src/debug_info.rs @@ -23,23 +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)?; - - Ok(()) + // Deref to `str`, which will use `FEATURE_DISABLED` if necessary + write!(f, "{}", &**self) } } impl fmt::Debug for DebugName { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - #[cfg(feature = "debug")] - write!(f, "{:?}", self.name.as_ref())?; - #[cfg(not(feature = "debug"))] - f.debug_struct("DebugName").finish()?; - - Ok(()) + // Deref to `str`, which will use `FEATURE_DISABLED` if necessary + write!(f, "{:?}", &**self) } } }