Skip to content

Conversation

@chescock
Copy link
Contributor

Objective

As noted in #21856, the Debug output of DebugName is too verbose. It is supposed to be a thin wrapper around a string, but it renders as a struct.

Solution

Manually impl Debug for DebugName and write the string directly.

Showcase

The following code

#[derive(Debug)]
struct TestStruct {
    debug_name: DebugName,
}
let test_struct = TestStruct {
    debug_name: DebugName::type_name::<TestStruct>(),
};
println!("{test_struct:#?}");

Prints the following before this change

TestStruct {
    debug_name: DebugName {
        name: "crate_name::TestStruct",
    },
}

And the following after it

TestStruct {
    debug_name: "crate_name::TestStruct",
}

When the debug feature is disabled, it prints the following both before and after the change

TestStruct {
    debug_name: DebugName,
}

@chescock chescock added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Utils Utility functions and types S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 17, 2025
#[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.

Copy link
Contributor

@ickshonpe ickshonpe left a comment

Choose a reason for hiding this comment

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

Looks good to me, maybe with the debug feature prompt suggested by janhohenheim.

@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Utils Utility functions and types C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants