1A radioactive stabilization of the [`ptr_meta` RFC][rfc]. 2 3[rfc]: https://rust-lang.github.io/rfcs/2580-ptr-meta.html 4 5# Usage 6 7## Sized types 8 9All `Sized` types have `Pointee` implemented for them with a blanket implementation. You do not 10need to derive `Pointee` for these types. 11 12## `slice`s and `str`s 13 14These core types have implementations built in. 15 16# `dyn Any` 17 18The trait object for this standard library type comes with an implementation built in. 19 20## Structs with a DST as its last field 21 22You can derive `Pointee` for structs with a trailing DST: 23 24```rust 25use ptr_meta::Pointee; 26 27#[derive(Pointee)] 28struct Block<H, T> { 29 header: H, 30 elements: [T], 31} 32``` 33 34Note that this will only work when the last field is guaranteed to be a DST. Structs with a 35generic last field may have a conflicting blanket impl since the generic type may be `Sized`. In 36these cases, a collection of specific implementations may be required with the generic parameter 37set to a slice, `str`, or specific trait object. 38 39## Trait objects 40 41You can generate a `Pointee` implementation for trait objects: 42 43```rust 44use ptr_meta::pointee; 45 46// Generates Pointee for dyn Stringy 47#[pointee] 48trait Stringy { 49 fn as_string(&self) -> String; 50} 51``` 52