Implement safe metadata Debug output
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::TypeErasedVec;
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::ManuallyDrop;
|
||||
|
||||
@@ -11,6 +12,17 @@ pub struct ContentGuard<'vec, T> {
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> fmt::Debug for ContentGuard<'_, T> {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter
|
||||
.debug_struct("ContentGuard")
|
||||
.field("layout", &self.erased.layout())
|
||||
.field("length", &self.erased.length())
|
||||
.field("capacity", &self.erased.capacity())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'vec, T> ContentGuard<'vec, T> {
|
||||
pub(crate) fn new_scoped(erased: &'vec mut TypeErasedVec) -> Self {
|
||||
debug_assert!(!std::mem::needs_drop::<T>());
|
||||
|
||||
+12
@@ -12,6 +12,7 @@ pub use guard::ContentGuard;
|
||||
pub use send::{SendSyncTypeErasedVec, SendTypeErasedVec, SendableTypeErasedVec};
|
||||
|
||||
use std::alloc::Layout;
|
||||
use std::fmt;
|
||||
use vtable::TypeErasedVecVtable;
|
||||
|
||||
use crate::parts::VecParts;
|
||||
@@ -50,6 +51,17 @@ pub struct TypeErasedVec {
|
||||
pub(crate) vtable: TypeErasedVecVtable,
|
||||
}
|
||||
|
||||
impl fmt::Debug for TypeErasedVec {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter
|
||||
.debug_struct("TypeErasedVec")
|
||||
.field("layout", &self.layout)
|
||||
.field("length", &self.parts.len)
|
||||
.field("capacity", &self.parts.cap)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeErasedVec {
|
||||
/// Type erase the underlying Capacity of a `Vec` remembering the `Layout` it was allocated with.
|
||||
/// Elements inside the `Vec` are retained.
|
||||
|
||||
+12
@@ -1,5 +1,6 @@
|
||||
use crate::{ContentGuard, TypeErasedVec};
|
||||
use std::alloc::Layout;
|
||||
use std::fmt;
|
||||
|
||||
macro_rules! define_thread_safe_erased_vec {
|
||||
(
|
||||
@@ -10,6 +11,17 @@ macro_rules! define_thread_safe_erased_vec {
|
||||
$(#[$meta])*
|
||||
pub struct $name(TypeErasedVec);
|
||||
|
||||
impl fmt::Debug for $name {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter
|
||||
.debug_struct(stringify!($name))
|
||||
.field("layout", &self.0.layout())
|
||||
.field("length", &self.0.length())
|
||||
.field("capacity", &self.0.capacity())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl $name {
|
||||
/// Type erase a vector while retaining its elements and allocation.
|
||||
#[must_use]
|
||||
|
||||
Reference in New Issue
Block a user