enum_collections/lib.rs
1//!# Enum collections
2//!
3//! See [EnumMap] for usage details.
4//!
5//! A map of enum variants to values. EnumMap is a fixed-size map, where each variant of the enum is mapped to a value.
6//! This implementation of EnumMap uses **safe Rust** only and is a a zero-cost abstraction over an array (**const-sized**),
7//! where the index of the array corresponds to the position of the variant in the enum.
8//!
9//! Because it is a thin wrapper over an array, it is stack-allocated by default. Simply `std::boxed::Box`ing it will move it to the heap, at the caller's discretion.
10//!- Indexed by enum variants.
11//!- IndexMut by enum variants.
12//!- Debug if the enum is Debug.
13//!- PartialEq if the value is PartialEq. Same for Eq.
14//!
15//!Debug and Eq are optional features. They are enabled by default.
16//!
17//!
18mod enumerated;
19mod enummap;
20#[cfg(feature = "ext")]
21mod ext;
22#[cfg(feature = "serde")]
23mod serde;
24
25pub use crate::enumerated::Enumerated;
26pub use crate::enummap::EnumMap;
27pub use enum_collections_macros::Enumerated;
28
29#[cfg(test)]
30mod tests {
31 use crate::Enumerated;
32
33 #[test]
34 fn test_derive_macro() {
35 #[derive(Enumerated)]
36 enum Letter {
37 A,
38 B,
39 }
40
41 assert_eq!(0, Letter::A.position());
42 assert_eq!(1, Letter::B.position());
43 assert_eq!(2, Letter::SIZE);
44 }
45}