Crates.io | ctti |
lib.rs | ctti |
version | 0.2.0 |
source | src |
created_at | 2023-01-12 12:32:54.608225 |
updated_at | 2023-01-24 15:06:47.727895 |
description | Compile-time type information |
homepage | |
repository | https://github.com/h33p/ctti |
max_upload_size | |
id | 757094 |
size | 40,460 |
This crate is an experimental standard library side implementation of potential ctti language feature.
The idea is to provide a function const fn type_info<T: ?Sized>() -> &'static Type
which
encodes the underlying type. Other crates can then build on top of this to provide advanced
features, such as:
TypeId
.Type
s across libraries.None of the above need to be implemented by the standard library. Everything can be built on top of compile-time type information.
Why not just this crate?
To be useful, the type information should be available to all types. Implementing it on primitives is simple, however, user types (structs, enums, unions) are impossible without either:
1 is the current state of many crates, such as abi_stable
, safer_ffi
. See
impls
module with example of how we do it. It works, however, it is
incredibly invasive - production code requires heavy modification to the crate, and
downstream crates cannot be used by them for the purposes of type layout checks.
2 becomes the only feasible solution. Depending on how advanced it is, it can also nicely handle things like self-referential structures without requiring runtime processing.
License: MIT