Crates.io | typeless |
lib.rs | typeless |
version | 0.1.0 |
source | src |
created_at | 2021-10-05 20:58:58.349524 |
updated_at | 2021-10-05 20:58:58.349524 |
description | `unsafe` inline type erasure |
homepage | https://www.crates.io/crates/typeless |
repository | https://github.com/Cyborus04/typeless/ |
max_upload_size | |
id | 460871 |
size | 20,238 |
unsafe
API for type erasure on the stack
Add the following to your Cargo.toml
[dependencies]
typeless = "0.1"
Storing any value x
of type T
in TypeErased
completely destroys all type data associated
with it.
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 parameter C
, 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
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
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.