Trait Pointee
pub unsafe trait Pointee {
type Metadata: Copy + Send + Sync + Ord + Hash + Unpin;
}
Available on crate feature
dep_rkyv
only.Expand description
A trait which associates pointer metadata with a pointee type.
§Pointer metadata
Pointers and references can be thought of as having two parts: a data address and some extra “pointer metadata”.
Pointers to statically-sized types and extern
types are
“narrow”: their pointer metadata is ()
.
Pointers to dynamically-sized types are “wide”: they have pointer metadata with a non-zero size. There are four classes of dynamically-sized types currently available:
str
s haveusize
pointer metadata equal to the length of the string slice in bytes.- Slices like
[i32]
haveusize
pointer metadata equal to the length of the slice in items. - Trait objects like
dyn SomeTrait
haveDynMetadata
pointer metadata, which point to the trait objects’ virtual method tables. - Structs with a trailing DST have the same metadata as the trailing DST.
In the future, Rust may add new kinds of types which have different pointer metadata.
§Safety
The associated Metadata
type must be the pointer metadata type for the
implementing type.