8 releases
0.3.0-pre1 | Nov 4, 2023 |
---|---|
0.3.0-alpha.2 | Mar 30, 2024 |
0.2.0 | Aug 10, 2022 |
0.1.4 | Jul 9, 2021 |
0.1.1 | Feb 19, 2021 |
#15 in No standard library
1,189,816 downloads per month
Used in 554 crates
(11 directly)
21KB
313 lines
ptr_meta
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 provided.
CStr
and OsStr
These std types have implementations provided when the std
feature is
enabled.
dyn Any
and dyn Error
These trait objects have implementations provided.
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;
}
Dependencies
~315–760KB
~18K SLoC