MCPcopy Index your code
hub / github.com/artichoke/intaglio

github.com/artichoke/intaglio @v1.15.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.15.1 ↗ · + Follow
356 symbols 627 edges 19 files 94 documented · 26%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

intaglio

GitHub Actions Code Coverage Twitter

Crate API

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.15.1"

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(())
}

Or intern bstr byte strings like:

use bstr::{BStr, BString};

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

Or intern C strings like:

use std::ffi::{CStr, CString};

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

Or intern platform strings like:

use std::ffi::{OsStr, OsString};

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

Or intern path strings like:

use std::path::{Path, PathBuf};

fn intern_and_get() -> Result<(), Box<dyn std::error::Error>> {
    let mut table = intaglio::path::SymbolTable::new();
    let name: &'static Path = Path::new("abc");
    let sym = table.intern(name)?;
    let retrieved = table.get(sym);
    assert_eq!(Some(name), retrieved);
    assert_eq!(sym, table.intern(PathBuf::from("abc"))?);
    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 string table features except bstr are enabled by default.

  • bstr - Enables an additional symbol table implementation for interning [bstr] byte strings (bstr::BString and &'static bstr::BStr). This feature is disabled 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 (CString and &'static CStr).
  • osstr - Enables an additional symbol table implementation for interning platform strings (OsString and &'static OsStr).
  • path - Enables an additional symbol table implementation for interning path strings (PathBuf and &'static Path).

Minimum Supported Rust Version

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

License

intaglio is licensed under either of:

Core symbols most depended-on inside this repo

intern
called by 31
src/str.rs
get
called by 14
src/str.rs
intern
called by 13
src/osstr.rs
id
called by 13
src/lib.rs
intern
called by 13
src/bstr.rs
intern
called by 13
src/bytes.rs
intern
called by 13
src/cstr.rs
intern
called by 13
src/path.rs

Shape

Method 226
Function 97
Class 31
Enum 2

Languages

Rust100%

Modules by API surface

src/str.rs46 symbols
src/path.rs46 symbols
src/osstr.rs46 symbols
src/cstr.rs46 symbols
src/bytes.rs46 symbols
src/bstr.rs46 symbols
src/internal.rs23 symbols
src/lib.rs18 symbols
tests/unwind_safety.rs12 symbols
src/convert.rs9 symbols
src/rollback.rs8 symbols
tests/leak_drop/main.rs3 symbols

For agents

$ claude mcp add intaglio \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact