intaglio
UTF-8 string and byte string interner and symbol table. Used to implement
storage for the Ruby Symbol table and the constant name table in
Artichoke Ruby.
Symbol objects represent names and some strings inside the Ruby interpreter. They are generated using the
:nameand:"string"literals syntax, and by the variousto_symmethods. The sameSymbolobject will be created for a given name or string for the duration of a program's execution, regardless of the context or meaning of that name.
Intaglio is a UTF-8 and byte string interner, which means it stores a single
copy of an immutable &str or &[u8] that can be referred to by a stable u32
token.
Interned strings and byte strings are cheap to compare and copy because they are
represented as a u32 integer.
Intaglio is an alternate name for an engraved gem, a gemstone that has been carved with an image. The Intaglio crate is used to implement an immutable Symbol store in Artichoke Ruby.
Usage
Add this to your Cargo.toml:
[]
= "1.12.0"
Then intern UTF-8 strings like:
Or intern byte strings like:
Or intern C strings like:
use ;
Or intern platform strings like:
use ;
Or intern path strings like:
use ;
Implementation
Intaglio interns owned and borrowed strings with no additional copying by
leveraging Cow and a bit of unsafe code. CI runs drop tests under Miri and
LeakSanitizer.
Crate features
All features are enabled by default.
- bytes - Enables an additional symbol table implementation for interning
byte strings (
Vec<u8>and&'static [u8]). - cstr - Enables an additional symbol table implementation for interning C
strings (
CStringand&'static CStr). - osstr - Enables an additional symbol table implementation for interning
platform strings (
OsStringand&'static OsStr). - path - Enables an additional symbol table implementation for interning
path strings (
PathBufand&'static Path).
Minimum Supported Rust Version
This crate requires at least Rust 1.81.0. This version can be bumped in minor releases.
License
intaglio is licensed under the MIT License (c) Ryan Lopopolo.