Struct DynMetadata
pub struct DynMetadata<Dyn: PointeeSized> { pub(in ::ptr::metadata) _vtable_ptr: NonNull<VTable>, pub(in ::ptr::metadata) _phantom: PhantomData<Dyn> }
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_placeimpl (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>_phantom: PhantomData<Dyn>
Implementations
impl<Dyn: PointeeSized> DynMetadata<Dyn>
fn vtable_ptr(self) -> *const VTableWhen
DynMetadataappears as the metadata field of a wide pointer, the rustc_middle layout computation does magic and the resulting layout is not aFieldsShape::Aggregate, instead it is aFieldsShape::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 ofDynMetadata. To work around that issue, we usetransmuteinstead of using a field projection.fn size_of(self) -> usizeReturns the size of the type associated with this vtable.
fn align_of(self) -> usizeReturns the alignment of the type associated with this vtable.
fn layout(self) -> LayoutReturns the size and alignment together as a
Layout
Trait Implementations
impl<Dyn: PointeeSized> Clone for DynMetadata<Dyn>
fn clone(&self) -> Self
impl<Dyn: PointeeSized> Copy for DynMetadata<Dyn>
impl<Dyn: PointeeSized> Debug for DynMetadata<Dyn>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<Dyn: PointeeSized> Eq for DynMetadata<Dyn>
impl<Dyn: PointeeSized> Hash for DynMetadata<Dyn>
fn hash<H: Hasher>(&self, hasher: &mut H)
impl<Dyn: PointeeSized> Ord for DynMetadata<Dyn>
fn cmp(&self, other: &Self) -> Ordering
impl<Dyn: PointeeSized> PartialEq for DynMetadata<Dyn>
fn eq(&self, other: &Self) -> bool
impl<Dyn: PointeeSized> PartialOrd for DynMetadata<Dyn>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl<Dyn: PointeeSized> Send for DynMetadata<Dyn>
impl<Dyn: PointeeSized> Sync for DynMetadata<Dyn>
impl<Dyn: PointeeSized> TrivialClone for DynMetadata<Dyn>
impl<Dyn: PointeeSized> Unpin for DynMetadata<Dyn>
Auto Trait Implementations
impl<Dyn> !RefUnwindSafe for DynMetadata<Dyn>
impl<Dyn> !UnwindSafe for DynMetadata<Dyn>
impl<Dyn> Freeze for DynMetadata<Dyn>
where
PhantomData<Dyn>: Freeze,
Dyn: ?Sized,
impl<Dyn> UnsafeUnpin for DynMetadata<Dyn>
where
PhantomData<Dyn>: UnsafeUnpin,
Dyn: ?Sized,
Blanket Implementations
impl<T> Any for DynMetadata<Dyn>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for DynMetadata<Dyn>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for DynMetadata<Dyn>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for DynMetadata<Dyn>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for DynMetadata<Dyn>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Printable for DynMetadata<Dyn>
where
T: Copy + Debug,
impl<T> SizeHint for DynMetadata<Dyn>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for DynMetadata<Dyn>
impl<T, U> Into<U> for DynMetadata<Dyn>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for DynMetadata<Dyn>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for DynMetadata<Dyn>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>