refcount_interner/
lib.rs

1// Copyright 2020 Ferdinand Bachmann
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8//! A simple reference-counted
9//! [interning](https://en.wikipedia.org/wiki/String_interning)
10//! library for strings, slices, and other data.
11//!
12//! This crate provides two kinds of owned interners that store the interned
13//! data in the reference-counted types `Rc<T>` or `Arc<T>`. When the
14//! `shrink_to_fit()` method is called on the interner, or when the interner is
15//! dropped, unused interned objects are deallocated.
16//!
17//! The two kinds of interners provided by this crate are `RcInterner` and
18//! `ArcInterner`, returning `Rc<T>` and `Arc<T>` objects respectively.
19//!
20//! # Example
21//!
22//! ```rust
23//! use std::rc::Rc;
24//! use refcount_interner::RcInterner;
25//!
26//! let mut interner = RcInterner::new();
27//!
28//! let hello = interner.intern_str("hello");
29//! let world = interner.intern_str("world");
30//!
31//! assert!(Rc::ptr_eq(&hello, &interner.intern_str("hello")));
32//! ```
33
34mod rc_interner;
35mod arc_interner;
36
37pub use rc_interner::RcInterner;
38pub use arc_interner::ArcInterner;