]> git.proxmox.com Git - rustc.git/blob - vendor/litemap/examples/language_names_lite_map.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / vendor / litemap / examples / language_names_lite_map.rs
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5 // LiteMap is intended as a small and low-memory drop-in replacement for HashMap.
6 //
7 // The reader may compare this LiteMap example with the HashMap example to see analogous
8 // operations between LiteMap and HashMap.
9
10 #![no_main] // https://github.com/unicode-org/icu4x/issues/395
11
12 icu_benchmark_macros::static_setup!();
13
14 use icu_locid::subtags::Language;
15 use icu_locid::subtags_language as language;
16 use litemap::LiteMap;
17
18 const DATA: [(Language, &str); 11] = [
19 (language!("ar"), "Arabic"),
20 (language!("bn"), "Bangla"),
21 (language!("ccp"), "Chakma"),
22 (language!("en"), "English"),
23 (language!("es"), "Spanish"),
24 (language!("fr"), "French"),
25 (language!("ja"), "Japanese"),
26 (language!("ru"), "Russian"),
27 (language!("sr"), "Serbian"),
28 (language!("th"), "Thai"),
29 (language!("tr"), "Turkish"),
30 ];
31
32 #[no_mangle]
33 fn main(_argc: isize, _argv: *const *const u8) -> isize {
34 icu_benchmark_macros::main_setup!();
35
36 let mut map = LiteMap::new_vec();
37 // https://github.com/rust-lang/rust/issues/62633 was declined :(
38 for (lang, name) in DATA.iter() {
39 map.try_append(lang, name).ok_or(()).unwrap_err();
40 }
41
42 assert_eq!(11, map.len());
43 assert_eq!(Some(&&"Thai"), map.get(&language!("th")));
44 assert_eq!(None, map.get(&language!("de")));
45
46 0
47 }