Expand description
A radioactive stabilization of the ptr_meta
RFC.
Usage
Sized types
All Sized
types have Pointee
implemented for them with a blanket implementation. You do not
need to derive Pointee
for these types.
slice
s and str
s
These core types have implementations built in.
dyn Any
The trait object for this standard library type comes with an implementation built in.
Structs with a DST as its last field
You can derive Pointee
for structs with a trailing DST:
use ptr_meta::Pointee;
#[derive(Pointee)]
struct Block<H, T> {
header: H,
elements: [T],
}
Note that this will only work when the last field is guaranteed to be a DST. Structs with a
generic last field may have a conflicting blanket impl since the generic type may be Sized
. In
these cases, a collection of specific implementations may be required with the generic parameter
set to a slice, str
, or specific trait object.
Trait objects
You can generate a Pointee
implementation for trait objects:
use ptr_meta::pointee;
// Generates Pointee for dyn Stringy
#[pointee]
trait Stringy {
fn as_string(&self) -> String;
}
Structs
The metadata for a Dyn = dyn SomeTrait
trait object type.
Traits
Extension methods for NonNull
.
Provides the pointer metadata type of any pointed-to type.
Extension methods for pointers.
Functions
Forms a (possibly wide) raw pointer from a data address and metadata.
Performs the same functionality as from_raw_parts
, except that a raw *mut
pointer is
returned, as opposed to a raw *const
pointer.
Returns the metadata component of a pointer.
Attribute Macros
Generates an implementation of Pointee
for trait objects.
Derive Macros
Generates an implementation of Pointee
for structs with a DST as its last
field.