Debian Codegraph @

third_party/rust/enum-map/README.md

raw
1 <!--
2 SPDX-FileCopyrightText: 2017 - 2023 Kamila Borowska <[email protected]>
3
4 SPDX-License-Identifier: MIT OR Apache-2.0
5 -->
6
7 # enum-map
8
9 A library providing enum map providing type safe enum array. It is
10 implemented using regular Rust arrays, so using them is as fast
11 as using regular Rust arrays.
12
13 This crate follows the "N minus two" MSRV policy. This means that it
14 supports the current Rust release, as well as the two before that.
15
16 ## Examples
17
18 ```rust
19 #[macro_use]
20 extern crate enum_map;
21
22 use enum_map::EnumMap;
23
24 #[derive(Debug, Enum)]
25 enum Example {
26 A,
27 B,
28 C,
29 }
30
31 fn main() {
32 let mut map = enum_map! {
33 Example::A => 1,
34 Example::B => 2,
35 Example::C => 3,
36 };
37 map[Example::C] = 4;
38
39 assert_eq!(map[Example::A], 1);
40
41 for (key, &value) in &map {
42 println!("{:?} has {} as value.", key, value);
43 }
44 }
45 ```