indexmap_nostd/lib.rs
1//! ### Disclaimer
2//!
3//! This is a reimplementation of the [`indexmap` crate] and meant
4//! to be a drop-in replacement for its [`indexmap::IndexMap`] and
5//! [`indexmap::IndexSet`] types in embedded `no_std` environments that cannot
6//! afford to use hash tables that require random seed initialization in order
7//! to _not_ be attackable by users controlling their inputs.
8//!
9//! This crate was originally and primarily conceived as building block for
10//! a similar [`wasmparser-nostd` crate] fork for embedded `no_std` environments.
11//! Therefore this crate currently only supports a subset of the features of
12//! the original [`indexmap` crate] that are required by the
13//! [`wasmparser-nostd` crate] initiative.
14//!
15//! ### Types
16//!
17//! [`IndexMap`] is a hash table where the iteration order of the key-value
18//! pairs is independent of the hash values of the keys.
19//!
20//! [`IndexSet`] is a corresponding hash set using the same implementation and
21//! with similar properties.
22//!
23//! [`wasmparser-nostd` crate]: https://crates.io/crates/wasmparser-nostd
24//! [`indexmap::IndexMap`]: https://docs.rs/indexmap/latest/indexmap/map/struct.IndexMap.html
25//! [`indexmap::IndexSet`]: https://docs.rs/indexmap/latest/indexmap/set/struct.IndexSet.html
26//! [`indexmap` crate]: https://crates.io/crates/indexmap
27//! [`IndexMap`]: map/struct.IndexMap.html
28//! [`IndexSet`]: set/struct.IndexSet.html
29//!
30//! ### Feature Highlights
31//!
32//! [`IndexMap`] and [`IndexSet`] are mostly drop-in compatible with the
33//! standard library's `HashMap` and `HashSet`.
34
35#![cfg_attr(not(feature = "std"), no_std)]
36
37#[cfg(feature = "std")]
38extern crate std as alloc;
39
40#[cfg(not(feature = "std"))]
41extern crate alloc;
42
43pub mod map;
44pub mod set;
45
46#[cfg(feature = "serde")]
47mod serde;
48
49#[cfg(feature = "serde")]
50pub mod serde_seq;
51
52pub use self::map::IndexMap;
53pub use self::set::IndexSet;
54
55/// A slot index referencing a slot in an [`IndexMap`].
56#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
57struct SlotIndex(usize);
58
59impl SlotIndex {
60 /// Returns the raw `usize` index of the [`SlotIndex`].
61 pub fn index(self) -> usize {
62 self.0
63 }
64}