pub struct DynMetadata<Dyn: ?Sized> {
_vtable_ptr: NonNull<VTable>,
_phantom: PhantomData<Dyn>,
}
ptr_metadata
#81513)Expand description
The metadata for a Dyn = dyn SomeTrait
trait object type.
It is a pointer to a vtable (virtual call table) that represents all the necessary information to manipulate the concrete type stored inside a trait object. The vtable notably contains:
- type size
- type alignment
- a pointer to the type’s
drop_in_place
impl (may be a no-op for plain-old-data) - pointers to all the methods for the type’s implementation of the trait
Note that the first three are special because they’re necessary to allocate, drop, and deallocate any trait object.
It is possible to name this struct with a type parameter that is not a dyn
trait object
(for example DynMetadata<u64>
) but not to obtain a meaningful value of that struct.
Note that while this type implements PartialEq
, comparing vtable pointers is unreliable:
pointers to vtables of the same type for the same trait can compare inequal (because vtables are
duplicated in multiple codegen units), and pointers to vtables of different types/traits can
compare equal (since identical vtables can be deduplicated within a codegen unit).
Fields§
§_vtable_ptr: NonNull<VTable>
ptr_metadata
#81513)_phantom: PhantomData<Dyn>
ptr_metadata
#81513)Implementations§
Source§impl<Dyn: ?Sized> DynMetadata<Dyn>
impl<Dyn: ?Sized> DynMetadata<Dyn>
Sourcefn vtable_ptr(self) -> *const VTable
🔬This is a nightly-only experimental API. (ptr_metadata
#81513)
fn vtable_ptr(self) -> *const VTable
ptr_metadata
#81513)When DynMetadata
appears as the metadata field of a wide pointer, the rustc_middle layout
computation does magic and the resulting layout is not a FieldsShape::Aggregate
, instead
it is a FieldsShape::Primitive
. This means that the same type can have different layout
depending on whether it appears as the metadata field of a wide pointer or as a stand-alone
type, which understandably confuses codegen and leads to ICEs when trying to project to a
field of DynMetadata
. To work around that issue, we use transmute
instead of using a
field projection.
Sourcepub fn size_of(self) -> usize
🔬This is a nightly-only experimental API. (ptr_metadata
#81513)
pub fn size_of(self) -> usize
ptr_metadata
#81513)Returns the size of the type associated with this vtable.
Trait Implementations§
Source§impl<Dyn: ?Sized> Clone for DynMetadata<Dyn>
impl<Dyn: ?Sized> Clone for DynMetadata<Dyn>
Source§impl<Dyn: ?Sized> Debug for DynMetadata<Dyn>
impl<Dyn: ?Sized> Debug for DynMetadata<Dyn>
Source§impl<Dyn: ?Sized> Eq for DynMetadata<Dyn>
impl<Dyn: ?Sized> Eq for DynMetadata<Dyn>
#[doc(hidden)] fn assert_receiver_is_total_eq(&self)
Source§impl<Dyn: ?Sized> Hash for DynMetadata<Dyn>
impl<Dyn: ?Sized> Hash for DynMetadata<Dyn>
Source§impl<Dyn: ?Sized> Ord for DynMetadata<Dyn>
impl<Dyn: ?Sized> Ord for DynMetadata<Dyn>
Source§impl<Dyn: ?Sized> PartialEq for DynMetadata<Dyn>
impl<Dyn: ?Sized> PartialEq for DynMetadata<Dyn>
Source§impl<Dyn: ?Sized> PartialOrd for DynMetadata<Dyn>
impl<Dyn: ?Sized> PartialOrd for DynMetadata<Dyn>
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Source§#[doc(hidden)] fn __chaining_lt(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_lt(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods
)self == other
, returns ControlFlow::Continue(())
.
Otherwise, returns ControlFlow::Break(self < other)
. Read moreSource§#[doc(hidden)] fn __chaining_le(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_le(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods
)__chaining_lt
, but for <=
instead of <
.Source§#[doc(hidden)] fn __chaining_gt(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_gt(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods
)__chaining_lt
, but for >
instead of <
.Source§#[doc(hidden)] fn __chaining_ge(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_ge(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods
)__chaining_lt
, but for >=
instead of <
.impl<Dyn: ?Sized> Copy for DynMetadata<Dyn>
impl<Dyn: ?Sized> Send for DynMetadata<Dyn>
impl<Dyn: ?Sized> Sync for DynMetadata<Dyn>
impl<Dyn: ?Sized> Unpin for DynMetadata<Dyn>
Auto Trait Implementations§
impl<Dyn> Freeze for DynMetadata<Dyn>where
Dyn: ?Sized,
impl<Dyn> !RefUnwindSafe for DynMetadata<Dyn>
impl<Dyn> UnsafeUnpin for DynMetadata<Dyn>where
Dyn: ?Sized,
impl<Dyn> !UnwindSafe for DynMetadata<Dyn>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties
)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties
)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties
)[Self]
. Read more