Provides the pointer metadata type of any pointed-to type.
Raw pointer types and reference types in Rust can be thought of as made of two parts: a data pointer that contains the memory address of the value, and some metadata.
For statically-sized types (that implement the
as well as for
pointers are said to be “thin”: metadata is zero-sized and its type is
Pointers to dynamically-sized types are said to be “wide” or “fat”, they have non-zero-sized metadata:
- For structs whose last field is a DST, metadata is the metadata for the last field
- For the
strtype, metadata is the length in bytes as
- For slice types like
[T], metadata is the length in items as
- For trait objects like
dyn SomeTrait, metadata is
In the future, the Rust language may gain new kinds of types that have different pointer metadata.
The point of this trait is its
Metadata associated type,
DynMetadata<_> as described above.
It is automatically implemented for every type.
It can be assumed to be implemented in a generic context, even without a corresponding bound.
Raw pointers can be decomposed into the data address and metadata components
Alternatively, metadata alone can be extracted with the
A reference can be passed to
metadata and implicitly coerced.
A (possibly-wide) pointer can be put back together from its address and metadata