Expand description

Simple, fast and allocation-free string interning.

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.

To generate intern-str graphs as code, see the [builder] module and the intern-str-codegen crate.

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.

Structs

The wrapper type for a string that is compared case-insensitively.
A deterministic finite automaton (DFA) that can be used to process sequential input to produce an output.
A node in a DFA.

Traits

An item that can be segmented into parts.