Skip to content

Commit dc034e6

Browse files
Fix entity display not working with padding. (#21850)
# Objective Attempting to display entities with padding does not work, no padding is added. ## Solution Fix the `fmt::Display` implementation of `Entity` so that padding works. ## Testing Added some unit tests for padding. Co-authored-by: François Mockers <francois.mockers@vleue.com>
1 parent 887672f commit dc034e6

File tree

1 file changed

+12
-2
lines changed
  • crates/bevy_ecs/src/entity

1 file changed

+12
-2
lines changed

crates/bevy_ecs/src/entity/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,13 @@ impl fmt::Debug for Entity {
671671
impl fmt::Display for Entity {
672672
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
673673
if self == &Self::PLACEHOLDER {
674-
write!(f, "PLACEHOLDER")
674+
f.pad("PLACEHOLDER")
675675
} else {
676-
write!(f, "{}v{}", self.index(), self.generation())
676+
f.pad(&alloc::fmt::format(format_args!(
677+
"{}v{}",
678+
self.index(),
679+
self.generation()
680+
)))
677681
}
678682
}
679683
}
@@ -1514,6 +1518,12 @@ mod tests {
15141518
let string = format!("{entity}");
15151519
assert_eq!(string, "42v0");
15161520

1521+
let padded_left = format!("{entity:<5}");
1522+
assert_eq!(padded_left, "42v0 ");
1523+
1524+
let padded_right = format!("{entity:>6}");
1525+
assert_eq!(padded_right, " 42v0");
1526+
15171527
let entity = Entity::PLACEHOLDER;
15181528
let string = format!("{entity}");
15191529
assert_eq!(string, "PLACEHOLDER");

0 commit comments

Comments
 (0)