Crates.io | type-equalities |
lib.rs | type-equalities |
version | 0.3.1 |
source | src |
created_at | 2021-05-06 03:24:08.048948 |
updated_at | 2022-01-04 17:15:50.330083 |
description | Observing type equality with zero-sized proofs |
homepage | https://github.com/WorldSEnder/type-equalities-rs |
repository | https://github.com/WorldSEnder/type-equalities-rs |
max_upload_size | |
id | 393668 |
size | 33,654 |
The central type, TypeEq<_, _>
, allows for zero-overhead, safe value coercions and is itself zero-sized.
Further, naming TypeEq<T, U>
is well-formed for any types, but an inhabitant is available only if the
equality holds. For trait-level type equality, T: IsEqual<U>
can be used.
The zero overhead claim can be seen in the provided benchmarks:
let eq = refl::<u32>().lift_through::<SliceF<BENCH_LEN>>();
b.iter(|| [0; BENCH_LEN]); // bench_no_coerce
b.iter(|| eq.coerce([0; BENCH_LEN])); // bench_coerce_array_refl
> running 2 tests
test benches::bench_no_coerce ... bench: 10,570 ns/iter (+/- 569)
test benches::bench_coerce_array_refl ... bench: 10,557 ns/iter (+/- 605)
This crate is no-std and has a (default: enabled) feature for alloc features, i.e. coercing Box
.
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.