mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
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 <alice.i.cecile@gmail.com>
This commit is contained in:
parent
b2e2f8d9e3
commit
df063ab1ef
1 changed files with 14 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::mem::MaybeUninit;
|
||||
use std::{fmt::Debug, mem::MaybeUninit};
|
||||
|
||||
use bevy_ptr::{OwningPtr, Unaligned};
|
||||
use bevy_utils::tracing::warn;
|
||||
|
@ -34,6 +34,19 @@ pub struct CommandQueue {
|
|||
bytes: Vec<MaybeUninit<u8>>,
|
||||
}
|
||||
|
||||
// CommandQueue needs to implement Debug manually, rather than deriving it, because the derived impl just prints
|
||||
// [core::mem::maybe_uninit::MaybeUninit<u8>, core::mem::maybe_uninit::MaybeUninit<u8>, ..] for every byte in the vec,
|
||||
// which gets extremely verbose very quickly, while also providing no useful information.
|
||||
// It is not possible to soundly print the values of the contained bytes, as some of them may be padding or uninitialized (#4863)
|
||||
// So instead, the manual impl just prints the length of vec.
|
||||
impl Debug for CommandQueue {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("CommandQueue")
|
||||
.field("len_bytes", &self.bytes.len())
|
||||
.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
// SAFETY: All commands [`Command`] implement [`Send`]
|
||||
unsafe impl Send for CommandQueue {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue