morphir_core/naming/interner.rs
1use lasso::{Spur, ThreadedRodeo};
2use std::sync::OnceLock;
3
4static INTERNER: OnceLock<ThreadedRodeo> = OnceLock::new();
5
6/// Returns a reference to the global string interner.
7pub fn interner() -> &'static ThreadedRodeo {
8 INTERNER.get_or_init(ThreadedRodeo::new)
9}
10
11/// A handle to an interned string (word).
12pub type Word = Spur;
13
14/// Interns a string and returns its handle.
15pub fn intern(s: &str) -> Word {
16 interner().get_or_intern(s)
17}
18
19/// Resolves an interned handle back to its string value.
20pub fn resolve(word: Word) -> &'static str {
21 interner().resolve(&word)
22}