]>
git.proxmox.com Git - rustc.git/blob - 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 ).
5 // LiteMap is intended as a small and low-memory drop-in replacement for HashMap.
7 // The reader may compare this LiteMap example with the HashMap example to see analogous
8 // operations between LiteMap and HashMap.
10 #![no_main] // https://github.com/unicode-org/icu4x/issues/395
12 icu_benchmark_macros
::static_setup
!();
14 use icu_locid
::subtags
::Language
;
15 use icu_locid
::subtags_language
as language
;
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"),
33 fn main(_argc
: isize, _argv
: *const *const u8) -> isize {
34 icu_benchmark_macros
::main_setup
!();
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();
42 assert_eq
!(11, map
.len());
43 assert_eq
!(Some(&&"Thai"), map
.get(&language
!("th")));
44 assert_eq
!(None
, map
.get(&language
!("de")));