The tyght-map crate provides a static type map implementation.
The map, [TyghtMap], enjoys the following properties:
- The size of the map will match the size of its items.
- No heap allocations, this crate is
!#[no_std]. - All methods on the map are infallible.
Example
# use *;
// Insert some different integer types into the map and check the size
let map = new
.insert
.insert
.insert;
assert_eq!;
// Retrieve the `u32` from the map
let item: &u32 = map.get;
assert_eq!;
// Insert a `String` into the map, then mutate it
let mut map = map.insert;
*map. += ", world!";
// Remove the `String` from the map
let = map.;
println!;
Traits
For each operation on [TyghtMap] there is an associated trait:
Contains<T>is implemented onSwhen it containsTallowinggetandremoveMissing<T>is implemented onSwhen it doesn't containTallowinginsert
This means that placing constraints on the S of TyghtMap<S> acts as a constraint on the items it contains.
For example, the following function cannot be called using a map which does not contain a String and a u32.
# use *;
Known Limitations
Currently, the map can only store 32 items. This limit can be raised if compile-times are known to be reasonable.
Future improvements to rustcs type system may remove the need for a limit all together.
Nightly
In contrast to other attempts, this implementation does not rely on specialization. It does however rely on a variety of nightly features:
These can be expected to be stabilized, in some form, before specialization.