icu_collections/char16trie/mod.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//! This module provides a data structure for a space-efficient and time-efficient lookup of
6//! sequences of 16-bit units (commonly but not necessarily UTF-16 code units)
7//! which map to integer values.
8//!
9//! It is an implementation of the existing [ICU4C UCharsTrie](https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1UCharsTrie.html)
10//! / [ICU4J CharsTrie](https://unicode-org.github.io/icu-docs/apidoc/released/icu4j/com/ibm/icu/util/CharsTrie.html) API.
11//!
12//! ## Architecture
13//!
14//! ICU4X [`Char16Trie`] is designed to provide a read-only view of `UCharsTrie` data that is exported from ICU4C.
15//!
16//! ## Examples
17//!
18//! ### Querying a `Char16Trie`
19//!
20//! ```rust
21//! use icu::collections::char16trie::Char16Trie;
22//! use zerovec::ZeroVec;
23//!
24//! // A Char16Trie containing the ASCII characters mapping 'a' to 1 and 'ab'
25//! // to 100.
26//! let trie_data = [48, 97, 176, 98, 32868];
27//! let trie = Char16Trie::new(ZeroVec::from_slice_or_alloc(&trie_data));
28//!
29//! let mut cursor = trie.cursor();
30//! cursor.step('a');
31//! assert_eq!(cursor.value(), Some(1));
32//! assert!(!cursor.is_empty());
33//! cursor.step('b');
34//! assert_eq!(cursor.value(), Some(100));
35//! assert!(cursor.is_empty());
36//! cursor.step('c');
37//! assert_eq!(cursor.value(), None);
38//! assert!(cursor.is_empty());
39//! ```
40//!
41//! [`ICU4X`]: ../icu/index.html
42
43mod trie;
44
45pub use trie::Char16Trie;
46pub use trie::Char16TrieCursor;
47#[allow(deprecated)]
48pub use trie::Char16TrieIterator;
49#[allow(deprecated)]
50pub use trie::TrieResult;