10 stable releases

Uses new Rust 2021

1.4.2 Nov 19, 2021
1.3.0 Aug 6, 2021
1.2.2 Jun 13, 2021
1.2.1 Feb 15, 2021
1.1.0 Jul 4, 2020

#7 in Caching

Download history 215/week @ 2021-08-09 339/week @ 2021-08-16 185/week @ 2021-08-23 708/week @ 2021-08-30 240/week @ 2021-09-06 234/week @ 2021-09-13 146/week @ 2021-09-20 372/week @ 2021-09-27 144/week @ 2021-10-04 139/week @ 2021-10-11 129/week @ 2021-10-18 184/week @ 2021-10-25 417/week @ 2021-11-01 191/week @ 2021-11-08 370/week @ 2021-11-15 331/week @ 2021-11-22

1,086 downloads per month
Used in lignin

MIT license

86KB
1.5K SLoC

intaglio

GitHub Actions Discord Twitter
Crate API API trunk

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 :name and :"string" literals syntax, and by the various to_sym methods. The same Symbol object 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:

[dependencies]
intaglio = "1.4"

Then intern UTF-8 strings like:

fn intern_and_get() -> Result<(), Box<dyn std::error::Error>> {
    let mut table = intaglio::SymbolTable::new();
    let name: &'static str = "abc";
    let sym = table.intern(name)?;
    let retrieved = table.get(sym);
    assert_eq!(Some(name), retrieved);
    assert_eq!(sym, table.intern("abc".to_string())?);
    Ok(())
}

Or intern byte strings like:

fn intern_and_get() -> Result<(), Box<dyn std::error::Error>> {
    let mut table = intaglio::bytes::SymbolTable::new();
    let name: &'static [u8] = b"abc";
    let sym = table.intern(name)?;
    let retrieved = table.get(sym);
    assert_eq!(Some(name), retrieved);
    assert_eq!(sym, table.intern(b"abc".to_vec())?);
    Ok(())
}

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]).

Minimum Supported Rust Version

This crate requires at least Rust 1.56.0. This version can be bumped in minor releases.

License

intaglio is licensed under the MIT License (c) Ryan Lopopolo.

No runtime deps