Expand description
unsafe
API for type erasure on the stack
Storing any value x
of type T
in TypeErased
completely destroys all type data associated
with it.
§Restrictions
While this erases all type data, leaving only the pure bytes, the compiler still requires 2 things:
-
Size: The size of a
TypeErased
is not based on the data it contains, but rather a const generic parameterC
, effectively a “maximum size” on the types it can contain. -
Alignment: Until there is a way to define alignment by a const parameter, the alignment of
TypeErased
is 8 bytes, so anything with an alignment of 8 or less can be contained
§Access
Since there is no type data anymore, any access to the inner data is unsafe
(except getting the bytes directly)
TypeErased
is not Send
nor Sync
since it can’t be known if that’s safe
Structs§
- Type
Erased - Type-erased data on the stack