Just print out name string, not the entire Name struct (#8494)

# Objective
This is just an oversight on my part when I implemented this in
https://github.com/bevyengine/bevy/pull/7186, there isn't much reason to
print out the hash of a `Name` like it does currently:
```
Name { hash: 1608798714325729304, name: "Suzanne" } (7v0)
```

## Solution
Instead it would be better if we just printed out the string like so:
```
"Suzanne" (7v0)
```

As it conveys all of the information in a less cluttered and immediately
intuitive way which was the original purpose of `DebugName`. Which I
also think translates to `Name` as well since I mostly see it as a thin
wrapper around a string.

---------

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
This commit is contained in:
Aceeri 2023-04-26 13:00:03 -07:00 committed by GitHub
parent 8ec4b99a69
commit c324b90ffe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,8 +17,8 @@ use std::{
/// [`Name`] should not be treated as a globally unique identifier for entities,
/// as multiple entities can have the same name. [`bevy_ecs::entity::Entity`] should be
/// used instead as the default unique identifier.
#[derive(Reflect, FromReflect, Component, Debug, Clone)]
#[reflect(Component, Default)]
#[derive(Reflect, FromReflect, Component, Clone)]
#[reflect(Component, Default, Debug)]
pub struct Name {
hash: u64, // TODO: Shouldn't be serialized
name: Cow<'static, str>,
@ -79,6 +79,13 @@ impl std::fmt::Display for Name {
}
}
impl std::fmt::Debug for Name {
#[inline(always)]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.name, f)
}
}
/// Convenient query for giving a human friendly name to an entity.
///
/// ```rust