Erase pointers of their concrete type and store type-erased pointers.
This is roughly equivalent to C's
There are two main useful reasons to type erase pointers in Rust:
- Removing viral generics from internal implementation details. If the internals truly don't care about the stored type, treating it opaquely reduces monomorphization cost both to the author and the compiler.
- Thin pointers to
?Sizedtypes. If an unsized type stores its metadata inline, then it can implement
Erasableand be used behind type-erased pointers. The type erased pointer does not have to carry the metadata, and the fat pointer can be recovered from the inline metadata. We provide the
Thinwrapper type to provide thin pointer types.
Wrapper struct to create thin pointer types.
A pointee type that supports type-erased pointers (thin pointers).
A (smart) pointer type that can be type-erased (making a thin pointer).
Erase a pointer.
A thin, type-erased pointer.