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:
Pixelstorm 2024-01-22 15:45:17 +00:00 committed by GitHub
parent b2e2f8d9e3
commit df063ab1ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
use std::mem::MaybeUninit; use std::{fmt::Debug, mem::MaybeUninit};
use bevy_ptr::{OwningPtr, Unaligned}; use bevy_ptr::{OwningPtr, Unaligned};
use bevy_utils::tracing::warn; use bevy_utils::tracing::warn;
@ -34,6 +34,19 @@ pub struct CommandQueue {
bytes: Vec<MaybeUninit<u8>>, 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`] // SAFETY: All commands [`Command`] implement [`Send`]
unsafe impl Send for CommandQueue {} unsafe impl Send for CommandQueue {}