Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion crates/bevy_utils/src/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe tell the user they can enable the debug feature to read the actual name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe tell the user they can enable the debug feature to read the actual name?

Yeah, that's a good idea! I had been trying to keep it consistent with the old version, but you're right that it's better to include the message. That also simplifies the implementation, since it can just use Deref.


Ok(())
}
}
}

impl DebugName {
Expand Down
Loading