Skip to content

Commit df063ab

Browse files
Implement Debug for CommandQueue (#11444)
# Objective Allow users to impl Debug on types containing `CommandQueue`s ## Solution Derive Debug on `CommandQueue` --------- Co-authored-by: Alice Cecile <[email protected]>
1 parent b2e2f8d commit df063ab

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/bevy_ecs/src/system/commands/command_queue.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::mem::MaybeUninit;
1+
use std::{fmt::Debug, mem::MaybeUninit};
22

33
use bevy_ptr::{OwningPtr, Unaligned};
44
use bevy_utils::tracing::warn;
@@ -34,6 +34,19 @@ pub struct CommandQueue {
3434
bytes: Vec<MaybeUninit<u8>>,
3535
}
3636

37+
// CommandQueue needs to implement Debug manually, rather than deriving it, because the derived impl just prints
38+
// [core::mem::maybe_uninit::MaybeUninit<u8>, core::mem::maybe_uninit::MaybeUninit<u8>, ..] for every byte in the vec,
39+
// which gets extremely verbose very quickly, while also providing no useful information.
40+
// It is not possible to soundly print the values of the contained bytes, as some of them may be padding or uninitialized (#4863)
41+
// So instead, the manual impl just prints the length of vec.
42+
impl Debug for CommandQueue {
43+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44+
f.debug_struct("CommandQueue")
45+
.field("len_bytes", &self.bytes.len())
46+
.finish_non_exhaustive()
47+
}
48+
}
49+
3750
// SAFETY: All commands [`Command`] implement [`Send`]
3851
unsafe impl Send for CommandQueue {}
3952

0 commit comments

Comments
 (0)