UTF-8 string and bytestring interner and symbol table

Used to implement storage

intaglio


. 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 bytestring 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 bytestrings 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.3"

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 bytestrings 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 bytestrings (Vec<u8> and &'static [u8]).

License

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

Versions

Find the latest versions by id

v1.6.1 - Apr 23, 2022

Release 1.6.1 of intaglio.

intaglio is available on crates.io.

Testing improvements

v1.6.0 - Mar 31, 2022

Release 1.6.0 of intaglio.

intaglio is available on crates.io.

Bug Fixes

v1.5.0 - Mar 31, 2022

Release 1.5.0 of intaglio.

intaglio is available on crates.io.

Improvements

This release includes several new interner implementations. intaglio now has an interner for all string types in the Rust standard library.

These new interners join the existing str/String and [u8]/Vec<u8> interners.

This release includes some code refactorings, packaging changes, and performance improvements:

v1.4.2 - Nov 19, 2021

Release 1.4.2 of intaglio.

intaglio is available on crates.io.

Improvements

This release includes several clarifications and improvements to API documentation:

v1.4.1 - Nov 19, 2021

Release 1.4.1 of intaglio.

intaglio is available on crates.io.

Improvements

This release includes several clarifications and improvements to API documentation:

v1.4.0 - Nov 18, 2021

Release 1.4.0 of intaglio.

intaglio is available on crates.io.

Improvements

Compatibility Notes

This release adds a documented minimum supported Rust version (MSRV) of 1.56.0. intaglio 1.4.0 will not build on Rust versions before 1.56.0. Changes to intaglio's MSRV will cause minor version bumps.

v1.3.0 - Aug 06, 2021

Release 1.3.0 of intaglio.

intaglio is available on crates.io.

Improvements

v1.2.2 - Jun 13, 2021

Release 1.2.2 of intaglio.

intaglio is available on crates.io.

This release adds feature callouts to the generated documentation on docs.rs using doc_cfg #75.

No Rust logic changed in this release.

v1.2.1 - Feb 15, 2021

Release 1.2.1 of intaglio.

intaglio is available on crates.io.

This release adds additional crates.io metadata and bumps the requirements on dev-dependencies.

No Rust logic changed in this release.

v1.2.0 - Dec 23, 2020

Release 1.2.0 of intaglio.

intaglio is available on crates.io.

Minimum Rust Version

intaglio requires Rust 1.46.0 to build because the crate makes use of match in const fn.

Improvements

  • Add more From and PartialEq implementations for Symbol. (GH-38)
  • Modify SymbolOverflowError so it is a zero-sized type. (GH-39)
  • Make SymbolOverflowError::new const. (GH-39)
  • Make SymbolOverflowError::max_capacity const. (GH-39)
  • Make Symbol::new const. (GH-40)
  • Make Symbol::id const. (GH-40)
  • Make internal Slice::as_slice and Interned::as_slice const. (GH-40)
  • Remove libc dev-dependency. (GH-49)

This release contains improvements to documentation and build process:

  • Miri tests are updated for latest nightly cargo-miri. (GH-46)
  • The test suite is run with LeakSanitizer. (GH-47, GH-49)

intaglio < 1.1.1 improperly declared the minimal versions of its dependencies. intaglio 1.2.0 has no dependencies. Using 1.2 as a minimal version is safe and is recommended in the README.

v1.1.1 - Aug 08, 2020

Release 1.1.1 of intaglio.

intaglio is available on crates.io.

Improvements

  • Remove dependency on bstr. intaglio now has zero runtime dependencies outside of std. (GH-29).
  • Reduce unsafe usage in crate internals. (GH-28, GH-31)
  • More aggressive inlining. (GH-30)
  • Optional UTF-8 formatting of bytes::SymbolTable when supplying the alternate format specifier {:#}. (GH-32)

This release contains improvements to documentation and build process.

v1.1.0 - Jul 04, 2020

Release 1.1.0 of intaglio.

New APIs

  • Add Symbol::id which returns the inner u32 (GH-25)
  • Add impl From<&Symbol> for {u32,u64,usize} (GH-25)

Improvements

  • Remove some dev-dependencies (GH-22)
  • Improve crate documentation and examples (GH-26)
  • Optimize layout of SymbolOverflowError (GH-25)

v1.0.1 - Jun 29, 2020

Release 1.0.1 of intaglio.

intaglio is a zero-copy UTF-8 and bytestring interner with a rich API.

Changes since v1.0.0

  • Fix cargo publish packaging errors. See GH-21.

v1.0.0 - Jun 29, 2020

Release 1.0.0 of intaglio.

intaglio is a zero-copy UTF-8 and bytestring interner with a rich API.

NOTE: This release was not published because it failed packaging on upload to crates.io. See GH-21.

Information - Updated May 13, 2022

Stars: 15
Forks: 2
Issues: 1

This is an example of a Rust server that functions as a remote schema for...

Rust + Hasura Rust server that functions as a Hasura

This is an example of a Rust server that functions as a remote schema for...

Newport Engine is a modular 2D and 3D game engine built in Rust for Rust

It is designed to be easily extendable and easy to use

Newport Engine is a modular 2D and 3D game engine built in Rust for Rust

Newport Engine is a modular 2D and 3D game engine built in Rust for Rust

It is designed to be easily extendable and easy to use

Newport Engine is a modular 2D and 3D game engine built in Rust for Rust

liboqs-rust: Rust bindings for liboqs

Qyantum Safe liboqs rust bindings

liboqs-rust: Rust bindings for liboqs

msgflo-rust: Rust participant support for MsgFlo

Flowhub visual programming IDE

msgflo-rust: Rust participant support for MsgFlo

Trojan-rust is a rust implementation for Trojan protocol that is targeted to circumvent GFW

Trojan protocol that is targeted to circumvent tokio-rs to achieve high performance async io

Trojan-rust is a rust implementation for Trojan protocol that is targeted to circumvent GFW
Actix

1.0K

How to be a full stack Rust Developer

Read Rust the Rust blog posts at Steadylearner

How to be a full stack Rust Developer

Rust library translation (rust-src/rust-std/stdlib/rustlib translation)

This is the place to translate Having a documentation in your native language is essential if you don't speak English, and still enjoyable even if...

Rust library translation (rust-src/rust-std/stdlib/rustlib translation)

False Positive for rust-lang/rust#83583

The deprecation lint proc_macro_derive_resolution_fallback is intended to catch proc macro generated code that refers to items from parent modules that should not be in scope:

False Positive for rust-lang/rust#83583

A CHIP-8 &amp; SuperChip interpreter written in Rust using rust-sdl2

If you're getting compile errors it may be because

A CHIP-8 &amp; SuperChip interpreter written in Rust using rust-sdl2

Rust-Svelte-on-Rust

Starter template for Rocket backend server

Rust-Svelte-on-Rust
Facebook Instagram Twitter GitHub Dribbble
Privacy