litemap/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//! # `litemap`
6//!
7//! `litemap` is a crate providing [`LiteMap`], a highly simplistic "flat" key-value map
8//! based off of a single sorted vector.
9//!
10//! The goal of this crate is to provide a map that is good enough for small
11//! sizes, and does not carry the binary size impact of [`HashMap`](std::collections::HashMap)
12//! or [`BTreeMap`](alloc::collections::BTreeMap).
13//!
14//! If binary size is not a concern, [`std::collections::BTreeMap`] may be a better choice
15//! for your use case. It behaves very similarly to [`LiteMap`] for less than 12 elements,
16//! and upgrades itself gracefully for larger inputs.
17//!
18//! ## Pluggable Backends
19//!
20//! By default, [`LiteMap`] is backed by a [`Vec`]; however, it can be backed by any appropriate
21//! random-access data store, giving that data store a map-like interface. See the [`store`]
22//! module for more details.
23//!
24//! ## Const construction
25//!
26//! [`LiteMap`] supports const construction from any store that is const-constructible, such as a
27//! static slice, via [`LiteMap::from_sorted_store_unchecked()`]. This also makes [`LiteMap`]
28//! suitable for use with [`databake`]. See [`impl Bake for LiteMap`] for more details.
29//!
30//! [`impl Bake for LiteMap`]: ./struct.LiteMap.html#impl-Bake-for-LiteMap<K,+V,+S>
31//! [`Vec`]: alloc::vec::Vec
32
33// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
34#![cfg_attr(not(any(test, doc)), no_std)]
35#![cfg_attr(
36 not(test),
37 deny(
38 clippy::indexing_slicing,
39 clippy::unwrap_used,
40 clippy::expect_used,
41 clippy::panic,
42 clippy::exhaustive_structs,
43 clippy::exhaustive_enums,
44 clippy::trivially_copy_pass_by_ref,
45 missing_debug_implementations,
46 )
47)]
48
49// for intra doc links
50#[cfg(doc)]
51extern crate std;
52
53#[cfg(feature = "alloc")]
54extern crate alloc;
55
56#[cfg(feature = "databake")]
57#[path = "databake.rs"] // to not conflict with `databake` as used in the docs
58mod databake_impls;
59mod map;
60#[cfg(feature = "serde")]
61mod serde;
62#[cfg(feature = "serde")]
63mod serde_helpers;
64pub mod store;
65
66#[cfg(any(test, feature = "testing"))]
67pub mod testing;
68
69pub use map::{Entry, LiteMap, OccupiedEntry, VacantEntry};