1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#![doc(html_root_url = "https://docs.rs/crate/string-interner/0.12.0")]
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(missing_docs)]

//! Caches strings efficiently, with minimal memory footprint and associates them with unique symbols.
//! These symbols allow constant time comparisons and look-ups to the underlying interned strings.
//!
//! ### Example: Interning & Symbols
//!
//! ```
//! use string_interner::StringInterner;
//!
//! let mut interner = StringInterner::default();
//! let sym0 = interner.get_or_intern("Elephant");
//! let sym1 = interner.get_or_intern("Tiger");
//! let sym2 = interner.get_or_intern("Horse");
//! let sym3 = interner.get_or_intern("Tiger");
//! assert_ne!(sym0, sym1);
//! assert_ne!(sym0, sym2);
//! assert_ne!(sym1, sym2);
//! assert_eq!(sym1, sym3); // same!
//! ```
//!
//! ### Example: Creation by `FromIterator`
//!
//! ```
//! # use string_interner::StringInterner;
//! let interner = vec!["Elephant", "Tiger", "Horse", "Tiger"]
//!     .into_iter()
//!     .collect::<StringInterner>();
//! ```
//!
//! ### Example: Look-up
//!
//! ```
//! # use string_interner::StringInterner;
//! let mut interner = StringInterner::default();
//! let sym = interner.get_or_intern("Banana");
//! assert_eq!(interner.resolve(sym), Some("Banana"));
//! ```
//!
//! ### Example: Iteration
//!
//! ```
//! # use string_interner::StringInterner;
//! let interner = vec!["Earth", "Water", "Fire", "Air"]
//!     .into_iter()
//!     .collect::<StringInterner>();
//! for (sym, str) in &interner {
//!     // iteration code here!
//! }
//! ```

#[cfg(feature = "serde-1")]
mod serde_impl;

pub mod backend;
mod compat;
mod interner;
pub mod symbol;

#[doc(inline)]
pub use self::{
    backend::DefaultBackend,
    compat::DefaultHashBuilder,
    interner::StringInterner,
    symbol::{
        DefaultSymbol,
        Symbol,
    },
};