1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/// Lightweight macro to automatically implement [`Enum`](crate::Enum).
///
/// The macro automatically implements [`Enum`](crate::Enum), it works only
/// on data less enums and automatically derives `Copy` and `Clone`.
///
/// # Example:
///
/// ```
/// use enumap::EnumMap;
///
/// enumap::enumap! {
/// /// A beautiful fruit, ready to be sold.
/// #[derive(Debug, PartialEq, Eq)]
/// enum Fruit {
/// Orange,
/// Banana,
/// Grape,
/// }
/// }
///
/// // A fruit shop: fruit -> stock.
/// let mut shop = EnumMap::new();
/// shop.insert(Fruit::Orange, 100);
/// shop.insert(Fruit::Banana, 200);
/// shop.insert(Fruit::Grape, 300);
///
/// assert_eq!(
/// shop.into_iter().collect::<Vec<_>>(),
/// vec![(Fruit::Orange, 100), (Fruit::Banana, 200), (Fruit::Grape, 300)],
/// );
///
/// // Oranges out of stock:
/// shop.remove(Fruit::Orange);
///
/// assert_eq!(
/// shop.into_iter().collect::<Vec<_>>(),
/// vec![(Fruit::Banana, 200), (Fruit::Grape, 300)],
/// );
/// # use enumap::Enum;
/// # assert_eq!(Fruit::to_index(Fruit::Orange), 0);
/// # assert_eq!(Fruit::to_index(Fruit::Banana), 1);
/// # assert_eq!(Fruit::to_index(Fruit::Grape), 2);
/// # assert!(matches!(Fruit::from_index(0), Some(Fruit::Orange)));
/// # assert!(matches!(Fruit::from_index(1), Some(Fruit::Banana)));
/// # assert!(matches!(Fruit::from_index(2), Some(Fruit::Grape)));
/// # assert!(matches!(Fruit::from_index(3), None));
/// # assert_eq!(Fruit::LENGTH, 3);
/// ```
) =>;
}