Expand description
A small library and custom derive to create a map-like struct that uses match expressions to get and insert values.
If you know your keys at compile-time, this library will likely be faster than HashMap for supported map operations.
Provides the following operations on the wrapping struct (via derive macros):
MyMap::get, returnsResult<Option<&V>, Error>MyMap::get_mut, returnsResult<Option<&mut V>, Error>MyMap::insert, returnsResult<Option<V>, Error>, whereVis the old value if one existsMyMap::remove, returnsResult<Option<V>, Error>MyMap::values, returns an iterator over&Vs
If you know that your operations cannot fail (e.g. if your key type is an enum, and you list all variants as keys),
you can add infallible = true to your derive attributes, which will unwrap the result of your map operations.
§Usage
fn main() {
pub enum A { A, B, C, D };
#[derive(Default, fast_map::FastMap)]
// We know this cannot fail, since we list all the `enum` variants, so we add `infallible = true`
#[fast_map(infallible = true, keys(A::A, A::B, A::C, A::D))]
struct Foo(fast_map::Map4<A, String>);
let mut foo = Foo::default();
foo.insert(A::B, "B".into());
assert_eq!(foo.get(A::B), Some(&"B".to_string()));
assert_eq!(foo.get(A::C), None);
foo.insert(A::C, "C".into());
assert_eq!(foo.values().collect::<Vec<_>>().len(), 2);
}§Changelog
§0.2.1
- Add the non-erroring operations back as depending on macro attribute (
infallible = true). Default isfalse.
§0.2.0
- Removed
easyandstrictMapLiketraits. It’s better to handle unknown keys explicitly, even forgets. - Added
get_mutoperation to the wrapping struct
Structs§
- Map1
- Container for a
mapwith 1 field - Map2
- Container for a
mapwith 2 fields - Map3
- Container for a
mapwith 3 fields - Map4
- Container for a
mapwith 4 fields - Map5
- Container for a
mapwith 5 fields - Map6
- Container for a
mapwith 6 fields - Map7
- Container for a
mapwith 7 fields - Map8
- Container for a
mapwith 8 fields - Map9
- Container for a
mapwith 9 fields - Map10
- Container for a
mapwith 10 fields - Map11
- Container for a
mapwith 11 fields - Map12
- Container for a
mapwith 12 fields - Map13
- Container for a
mapwith 13 fields - Map14
- Container for a
mapwith 14 fields - Map15
- Container for a
mapwith 15 fields - Map16
- Container for a
mapwith 16 fields - Map17
- Container for a
mapwith 17 fields - Map18
- Container for a
mapwith 18 fields - Map19
- Container for a
mapwith 19 fields - Map20
- Container for a
mapwith 20 fields - Map21
- Container for a
mapwith 21 fields - Map22
- Container for a
mapwith 22 fields - Map23
- Container for a
mapwith 23 fields - Map24
- Container for a
mapwith 24 fields - Map25
- Container for a
mapwith 25 fields - Map26
- Container for a
mapwith 26 fields - Map27
- Container for a
mapwith 27 fields - Map28
- Container for a
mapwith 28 fields - Map29
- Container for a
mapwith 29 fields - Map30
- Container for a
mapwith 30 fields - Map31
- Container for a
mapwith 31 fields - Map32
- Container for a
mapwith 32 fields - Map48
- Container for a
mapwith 48 fields - Map64
- Container for a
mapwith 64 fields - Values
- Iterator over existing values
Enums§
- Error
- Currently just
KeyNotFound