variant_map/
lib.rs

1//! Enum variants stored in Maps.
2//!
3//! Provides different kinds of map-equivalent types to store enum variants into.
4//! As those data structures are maps, they store one value of each variant.
5//! All Maps are [serde::Serialize]-able and [serde::Deserialize]-able
6//!
7//!
8//! Those maps can be generated easily using the derive macros from [variant_map_derive].
9//! [variant_map_derive] provides a derive macro for a `StructMap` (a struct type with a field per enum variant).
10//! [variant_map_derive] can be included using the `derive` feature on [variant_map][crate]
11//!
12//!
13//! This crate also provide simple [macros] to lighten the syntax.
14//!
15//!
16//! # Example
17//!
18//! ```
19//!     use variant_map_derive::VariantStore;
20//!
21//!     #[derive(VariantStore)]
22//!     enum MyEnum {
23//!         A,
24//!         B(i32),
25//!     }
26//!
27//!     fn main() {
28//!         use variant_map::{as_key, as_map};
29//!         let mut map = <as_map!(MyEnum)>::default();
30//!         let _: &MyEnum = map.get(&<as_key!(MyEnum)>::A).unwrap();
31//!         let _: &MyEnum = map.get(&MyEnumKey::A).unwrap();
32//!         map[&MyEnumKey::B] = MyEnum::B(69);
33//!     }
34//! ```
35//!
36//! For more customizability of the [Map][common::MapValue::Map] check out the [variant_map_derive] crate documentation
37//!
38//! For more detailed examples check out the [example project](https://github.com/mxyns/variant-map/tree/master/example) on this crates' [repo](https://github.com/mxyns/variant-map/)
39
40/// Code in common between [hashmap] and [btreemap]
41pub mod common;
42
43/// Used by the [variant_map_derive] to provide [serde::Serialize] and [serde::Deserialize] implementations
44pub use serde;
45
46/// A [hashmap::Map] storing Enum variants based on a [std::collections::HashMap]
47pub mod hashmap {
48    mod lib;
49    pub use lib::*;
50}
51
52/// A [btreemap::Map] storing Enum variants based on a [std::collections::BTreeMap]
53pub mod btreemap {
54    mod lib;
55    pub use lib::*;
56}
57
58/// Derive macro which derives an enum of keys and implements [common::MapValue] on your enum
59/// Available when using the *derive* or *struct-map* feature
60#[cfg(feature = "derive")]
61pub use variant_map_derive as derive;
62
63/// Helper [macros] to access the associated [Map][common::MapValue::Map] and [Key][common::MapValue::Key] types to an enum implementing [MapValue][common::MapValue]
64/// Available when using the *macros* feature
65#[cfg(feature = "macros")]
66pub mod macros;