| Crates.io | str_cache |
| lib.rs | str_cache |
| version | 0.1.1 |
| created_at | 2025-08-26 05:04:21.352787+00 |
| updated_at | 2025-08-26 05:19:34.514853+00 |
| description | A fast, lock-free, thread-safe string interning library |
| homepage | https://github.com/Tyler-Hardin/str_cache |
| repository | https://github.com/Tyler-Hardin/str_cache.git |
| max_upload_size | |
| id | 1810535 |
| size | 121,896 |
A lockfree string interning library for Rust.
String interning lets you store each unique string only once in memory, then reference it through lightweight handles. This is useful for programs that would otherwise end up with lots of duplicate String allocations or need to leak strings to &'static str.
&'static str referencesuse str_cache::{intern, get};
// Intern strings - duplicates share the same memory
let hello1 = intern("hello");
let hello2 = intern("hello"); // Same pointer as hello1
// Get string content back
assert_eq!(&*hello1, "hello");
// Look up existing strings
assert_eq!(get("hello"), Some(hello1));
assert_eq!(get("missing"), None);
For cases where you need multiple independent caches:
use str_cache::StrCache;
let cache = StrCache::new();
let handle = cache.intern("some string");
let content: &str = &*handle;
&str without copyingThe handles are small, cheap to copy, and implement all the standard traits (Eq, Ord, Hash, etc.) so you can use them as map keys, in collections, or anywhere you'd use a string.
MIT