Skip to content

Commit c65ef19

Browse files
authored
Friendlier Entity Debug impl (#20045)
# Objective The current Entity Debug impl prints the bit representation. This is an "overshare". Debug is in many ways the primary interface into Entity, as people derive Debug on their entity-containing types when they want to inspect them. The bits take up too much space in the console and obfuscate the useful information (entity index and generation). ## Solution Use the Display implementation in Debug as well. Direct people interested in bits to `Entity::to_bits` in the docs.
1 parent 1a3b26d commit c65ef19

File tree

1 file changed

+5
-31
lines changed
  • crates/bevy_ecs/src/entity

1 file changed

+5
-31
lines changed

crates/bevy_ecs/src/entity/mod.rs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -615,42 +615,16 @@ impl<'de> Deserialize<'de> for Entity {
615615
}
616616
}
617617

618-
/// Outputs the full entity identifier, including the index, generation, and the raw bits.
618+
/// Outputs the short entity identifier, including the index and generation.
619619
///
620-
/// This takes the format: `{index}v{generation}#{bits}`.
620+
/// This takes the format: `{index}v{generation}`.
621621
///
622622
/// For [`Entity::PLACEHOLDER`], this outputs `PLACEHOLDER`.
623623
///
624-
/// # Usage
625-
///
626-
/// Prefer to use this format for debugging and logging purposes. Because the output contains
627-
/// the raw bits, it is easy to check it against serialized scene data.
628-
///
629-
/// Example serialized scene data:
630-
/// ```text
631-
/// (
632-
/// ...
633-
/// entities: {
634-
/// 4294967297: ( <--- Raw Bits
635-
/// components: {
636-
/// ...
637-
/// ),
638-
/// ...
639-
/// )
640-
/// ```
624+
/// For a unique [`u64`] representation, use [`Entity::to_bits`].
641625
impl fmt::Debug for Entity {
642626
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
643-
if self == &Self::PLACEHOLDER {
644-
write!(f, "PLACEHOLDER")
645-
} else {
646-
write!(
647-
f,
648-
"{}v{}#{}",
649-
self.index(),
650-
self.generation(),
651-
self.to_bits()
652-
)
653-
}
627+
fmt::Display::fmt(self, f)
654628
}
655629
}
656630

@@ -1645,7 +1619,7 @@ mod tests {
16451619
fn entity_debug() {
16461620
let entity = Entity::from_raw(EntityRow::new(NonMaxU32::new(42).unwrap()));
16471621
let string = format!("{entity:?}");
1648-
assert_eq!(string, "42v0#4294967253");
1622+
assert_eq!(string, "42v0");
16491623

16501624
let entity = Entity::PLACEHOLDER;
16511625
let string = format!("{entity:?}");

0 commit comments

Comments
 (0)