Available on crate feature
osstr
only.Expand description
Intern platform strings.
This module provides a nearly identical API to the one found in the top-level of this crate. There is one important difference:
- Interned contents are
&OsStr
instead of&str
. Additionally,OsString
is used whereString
would have been used.
Example: intern platform string
let mut table = SymbolTable::new();
let sym = table.intern(OsStr::new("abc"))?;
assert_eq!(sym, table.intern(OsString::from("abc"))?);
assert_eq!(Some(OsStr::new("abc")), table.get(sym));
Example: symbol iterators
let mut table = SymbolTable::new();
let sym = table.intern(OsStr::new("abc"))?;
// Retrieve set of `Symbol`s.
let all_symbols = table.all_symbols();
assert_eq!(vec![sym], all_symbols.collect::<Vec<_>>());
table.intern(OsStr::new("xyz"))?;
let mut map = HashMap::new();
map.insert(Symbol::new(0), OsStr::new("abc"));
map.insert(Symbol::new(1), OsStr::new("xyz"));
// Retrieve symbol to platform string content mappings.
let iter = table.iter();
assert_eq!(map, iter.collect::<HashMap<_, _>>());
Performance
In general, one should expect this crate’s performance on &OsStr
to be
roughly similar to performance on &str
.
Structs
- An iterator over all
Symbol
s in aSymbolTable
. - An iterator over all symbols and interned platform strings in a
SymbolTable
. - An iterator over all interned platform strings in a
SymbolTable
. - Platform string interner.