Module symtern::adaptors [] [src]

Interner Adaptors

Each type in this module provides some additional functionality beyond that of Symtern's basic interner.

Adaptors are wrapper types, i.e. they "wrap" another interner type, taking it as a generic parameter.

use symtern::{Pool, Sym};
use symtern::adaptors::{Inline, InlineSym};

type MyPool = symtern::adaptors::Inline<symtern::Pool<str,u32>>;
type MySym = symtern::adaptors::InlineSym<symtern::Sym<u32>>;

Inline

By wrapping your Pool<str, _> type in the [Inline] adaptor, you can create an interner optimized for short strings. When input strings are under a certain length, this adaptor will store them directly in the returned symbols — entirely bypassing the wrapped interner. If you expect to be working with many short strings, it may perform better than the basic interner.

use symtern::prelude::*;
use symtern::adaptors::Inline;
use symtern::Pool;
let mut pool = Inline::from(Pool::<str,u64>::new());

if let (Ok(hello), Ok(world)) = (pool.intern("Hello"), pool.intern("World")) {
    assert!(hello != world);

    // Since both "hello" and "world" are smaller than the pool's
    // symbol representation (u64), neither symbol takes up any space
    // in the pool.
    assert!(pool.is_empty());
}

Luma

The Luma adaptor uses interior mutability via RefCell to allow its symbols to carry a lifetime parameter, which is used to prevent the pool from being dropped while it is in use.

For example, the following code will not compile because it attempts to return a symbol from a temporary Luma-wrapped interner.

Structs

Inline

Interner optimized for short strings.

InlineSym

Symbol type used by the short module's Intern implementation.

Luma

Interner adaptor that utilizes interior mutability to implement the Intern trait.

LumaSym

Symbol type used by the Luma adaptor.