zerotrie/lib.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//! A data structure offering zero-copy storage and retrieval of byte strings, with a focus
6//! on the efficient storage of ASCII strings. Strings are mapped to `usize` values.
7//!
8//! [`ZeroTrie`] does not support mutation because doing so would require recomputing the entire
9//! data structure. Instead, it supports conversion to and from [`LiteMap`] and [`BTreeMap`].
10//!
11//! There are multiple variants of [`ZeroTrie`] optimized for different use cases.
12//!
13//! # Examples
14//!
15//! ```
16//! use zerotrie::ZeroTrie;
17//!
18//! let data: &[(&str, usize)] = &[("abc", 11), ("xyz", 22), ("axyb", 33)];
19//!
20//! let trie: ZeroTrie<Vec<u8>> = data.iter().copied().collect();
21//!
22//! assert_eq!(trie.get("axyb"), Some(33));
23//! assert_eq!(trie.byte_len(), 18);
24//! ```
25//!
26//! # Internal Structure
27//!
28//! To read about the internal structure of [`ZeroTrie`], build the docs with private modules:
29//!
30//! ```bash
31//! cargo doc --document-private-items --all-features --no-deps --open
32//! ```
33//!
34//! [`LiteMap`]: litemap::LiteMap
35//! [`BTreeMap`]: alloc::collections::BTreeMap
36
37// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
38#![cfg_attr(not(any(test, doc)), no_std)]
39#![cfg_attr(
40 not(test),
41 deny(
42 // TODO(#4034): Enable the rest of these lints.
43 // clippy::indexing_slicing,
44 // clippy::unwrap_used,
45 clippy::expect_used,
46 // clippy::panic,
47 clippy::exhaustive_structs,
48 clippy::exhaustive_enums, clippy::trivially_copy_pass_by_ref,
49 missing_debug_implementations,
50 )
51)]
52#![warn(missing_docs)]
53
54#[cfg(feature = "alloc")]
55extern crate alloc;
56
57mod builder;
58mod byte_phf;
59pub mod cursor;
60mod error;
61#[macro_use]
62mod helpers;
63mod options;
64mod reader;
65#[cfg(feature = "serde")]
66mod serde;
67mod varint;
68mod zerotrie;
69
70pub use crate::zerotrie::ZeroAsciiIgnoreCaseTrie;
71pub use crate::zerotrie::ZeroTrie;
72pub use crate::zerotrie::ZeroTrieExtendedCapacity;
73pub use crate::zerotrie::ZeroTriePerfectHash;
74pub use crate::zerotrie::ZeroTrieSimpleAscii;
75pub use error::ZeroTrieBuildError;
76
77#[cfg(feature = "alloc")]
78pub use crate::zerotrie::ZeroTrieStringIterator;
79#[cfg(feature = "alloc")]
80pub use reader::ZeroTrieIterator;
81
82#[doc(hidden)]
83pub mod _internal {
84 pub use crate::byte_phf::f1;
85 pub use crate::byte_phf::f2;
86 pub use crate::byte_phf::PerfectByteHashMap;
87}