From 52e5ad5da7b59b2771cdec7b3637caa8a5c8a97e Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Tue, 25 Jun 2024 13:08:24 -0400 Subject: [PATCH] Don't show `.to_bits` in `Display` impl for `Entity` (#14011) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective #12469 changed the `Debug` impl for `Entity`, making sure it's actually accurate for debugging. To ensure that its can still be readily logged in error messages and inspectors, this PR added a more concise and human-friendly `Display` impl. However, users found this form too verbose: the `to_bits` information was unhelpful and too long. Fixes #13980. ## Solution - Don't include `Entity::to_bits` in the `Display` implementation for `Entity`. This information can readily be accessed and logged for users who need it. - Also clean up the implementation of `Display` for `DebugName`, introduced in https://github.com/bevyengine/bevy/pull/13760, to simply use the new `Display` impl (since this was the desired format there). ## Testing I've updated an existing test to verify the output of `Entity::display`. --------- Co-authored-by: Kristoffer Søholm --- crates/bevy_core/src/name.rs | 2 +- crates/bevy_ecs/src/entity/mod.rs | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/crates/bevy_core/src/name.rs b/crates/bevy_core/src/name.rs index c3012224ad..2efa8d619b 100644 --- a/crates/bevy_core/src/name.rs +++ b/crates/bevy_core/src/name.rs @@ -125,7 +125,7 @@ impl<'a> std::fmt::Display for DebugNameItem<'a> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self.name { Some(name) => std::fmt::Display::fmt(name, f), - None => write!(f, "{}v{}", self.entity.index(), self.entity.generation()), + None => std::fmt::Display::fmt(&self.entity, f), } } } diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 5cefe6a1df..656687cdcd 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -392,13 +392,7 @@ impl<'de> Deserialize<'de> for Entity { impl fmt::Display for Entity { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{}v{}|{}", - self.index(), - self.generation(), - self.to_bits() - ) + write!(f, "{}v{}", self.index(), self.generation()) } } @@ -1162,9 +1156,7 @@ mod tests { 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)); } }