ctti

Crates.ioctti
lib.rsctti
version0.2.0
sourcesrc
created_at2023-01-12 12:32:54.608225
updated_at2023-01-24 15:06:47.727895
descriptionCompile-time type information
homepage
repositoryhttps://github.com/h33p/ctti
max_upload_size
id757094
size40,460
Auri (h33p)

documentation

https://docs.rs/ctti

README

Compile-Time Type Information

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:

  1. Stable TypeId.
  2. Safe dynamic linking by comparing 2 Types across libraries.
  3. Reflection.

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. Wrapping every type with a macro.
  2. Compiler support.

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

Commit count: 2

cargo fmt