Module intaglio::path

source ·
Available on crate feature path only.
Expand description

Intern path strings.

This module provides a nearly identical API to the one found in the top-level of this crate. There is one important difference:

  1. Interned contents are &Path instead of &str. Additionally, PathBuf is used where String would have been used.

§Example: intern path string

let mut table = SymbolTable::new();
let sym = table.intern(Path::new("abc"))?;
assert_eq!(sym, table.intern(PathBuf::from("abc"))?);
assert_eq!(Some(Path::new("abc")), table.get(sym));

§Example: symbol iterators

let mut table = SymbolTable::new();
let sym = table.intern(Path::new("abc"))?;
// Retrieve set of `Symbol`s.
let all_symbols = table.all_symbols();
assert_eq!(vec![sym], all_symbols.collect::<Vec<_>>());

table.intern(Path::new("xyz"))?;
let mut map = HashMap::new();
map.insert(Symbol::new(0), Path::new("abc"));
map.insert(Symbol::new(1), Path::new("xyz"));
// Retrieve symbol to path string content mappings.
let iter = table.iter();
assert_eq!(map, iter.collect::<HashMap<_, _>>());

§Performance

In general, one should expect this crate’s performance on &Path to be roughly similar to performance on &str.

Structs§