Module intaglio::bytes [−][src]
Intern arbitrary bytes.
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
&[u8]
instead of&str
. Additionally,Vec<u8>
is used whereString
would have been used.
Example: intern bytestring
let mut table = SymbolTable::new(); let sym = table.intern(&b"abc"[..])?; assert_eq!(sym, table.intern(b"abc".to_vec())?); assert_eq!(Some(&b"abc"[..]), table.get(sym));
Example: symbol iterators
let mut table = SymbolTable::new(); let sym = table.intern(&b"abc"[..])?; // Retrieve set of `Symbol`s. let all_symbols = table.all_symbols(); assert_eq!(vec![sym], all_symbols.collect::<Vec<_>>()); table.intern(&b"xyz"[..])?; let mut map = HashMap::new(); map.insert(Symbol::new(0), &b"abc"[..]); map.insert(Symbol::new(1), &b"xyz"[..]); // Retrieve symbol to byte content mappings. let iter = table.iter(); assert_eq!(map, iter.collect::<HashMap<_, _>>());
Performance
In general, one should expect this crate's performance on &[u8]
to be
roughly similar to performance on &str
.
Structs
AllSymbols | An iterator over all |
Bytestrings | An iterator over all interned bytestrings in a |
Iter | An iterator over all symbols and interned bytestrings in a |
SymbolTable | Byte string interner. |