Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistency between Debug and serialized representation of Entity #12469

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Changes from all commits
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
22 changes: 19 additions & 3 deletions crates/bevy_ecs/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type IdCursor = isize;
/// [`Query::get`]: crate::system::Query::get
/// [`World`]: crate::world::World
/// [SemVer]: https://semver.org/
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
#[cfg_attr(
feature = "bevy_reflect",
Expand Down Expand Up @@ -384,9 +384,15 @@ impl<'de> Deserialize<'de> for Entity {
}
}

impl fmt::Debug for Entity {
impl fmt::Display for Entity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}v{}", self.index(), self.generation())
write!(
f,
"{}v{}|{}",
self.index(),
self.generation(),
self.to_bits()
)
}
}

Expand Down Expand Up @@ -1147,4 +1153,14 @@ mod tests {
assert_ne!(hash, first_hash);
}
}

#[test]
fn entity_display() {
let entity = Entity::from_raw(42);
let string = format!("{}", entity);
let bits = entity.to_bits().to_string();
assert!(string.contains("42"));
assert!(string.contains("v1"));
assert!(string.contains(&bits));
}
}