2 releases

0.1.1 Jan 12, 2025
0.1.0 Jan 11, 2025

#21 in #interning

Download history 77/week @ 2025-01-05 191/week @ 2025-01-12

268 downloads per month

MIT license

11KB
240 lines

Object interner in Rust


lib.rs:

An object interner library

The main element of this crate is the Interner struct.

It allows to build a "storage" of any kind of object that avoids repetition and memory waste.

Example (String interner)

use interns::*;

let mut interner = Interner::<str>::default();

let a = interner.get_or_intern("hello");
let b = interner.get_or_intern("world");
let c = interner.get_or_intern("hello");

let a_resolv = interner.resolve(a);
let b_resolv = interner.resolve(b);
let c_resolv = interner.resolve(c);

assert_eq!(a_resolv, Some("hello"));
assert_eq!(b_resolv, Some("world"));
assert_eq!(c_resolv, Some("hello"));

assert_eq!(a, c);
assert_ne!(a, b);
assert_ne!(b, c);

Dependencies

~1MB
~12K SLoC