intern-str

Crates.iointern-str
lib.rsintern-str
version0.1.0
sourcesrc
created_at2022-09-25 20:02:58.325816
updated_at2022-09-25 20:02:58.325816
descriptionEfficient, compile-time string interning for Rust
homepagehttps://github.com/notgull/intern-str#readme
repositoryhttps://github.com/notgull/intern-str
max_upload_size
id673786
size47,808
John Nunley (notgull)

documentation

https://docs.rs/intern-str

README

intern-str

intern-str is a library for interning strings in Rust. It allows you to build a graph that can convert strings (and byte strings) into arbitrary values. In addition, these graphs are no_std and can be embedded into projects at compile time.

The goal is to allow for low-cost, efficient string interning that does not require an allocator or the standard library. The intended use case is MIME Types, but it is likely to be useful in many other cases as well.

intern-str is no_std, no extern crate alloc, forbid(unsafe_code), and has no dependencies aside from the Rust core library.

Implementation

intern-str generates a DFA consisting of all possible options for a given set of strings. This DFA is then used to convert a string into a value. The DFA is generated at compile time, and is embedded into the binary. This allows for efficient string interning without the need for an allocator or the standard library.

In many cases, this approach is significantly faster than converting the string to lowercase and matching on it. When matching on /usr/share/dict/words, intern-str usually completes queries in 50 ns.

The main advantage of this approach is that it can be used to create case-insensitive matching, which is significantly more difficult to do with other libraries like phf. When compared against phf when phf has to convert strings to lower case before running, intern-str is usually as fast as phf if not faster.

MSRV

The current Minimum Safe Rust Version (MSRV) is Rust 1.31.0. Any change in the MSRV will lead to a minor version bump at minimum.

License

intern_str is licensed under one of the following:

at your option.

Commit count: 13

cargo fmt