string_interner::backend

Trait Backend

Source
pub trait Backend: Default {
    type Symbol: Symbol;
    type Iter<'a>: Iterator<Item = (Self::Symbol, &'a str)>
       where Self: 'a;

    // Required methods
    fn with_capacity(cap: usize) -> Self;
    fn intern(&mut self, string: &str) -> Self::Symbol;
    fn shrink_to_fit(&mut self);
    fn resolve(&self, symbol: Self::Symbol) -> Option<&str>;
    unsafe fn resolve_unchecked(&self, symbol: Self::Symbol) -> &str;
    fn iter(&self) -> Self::Iter<'_>;

    // Provided method
    fn intern_static(&mut self, string: &'static str) -> Self::Symbol { ... }
}
Expand description

Types implementing this trait may act as backends for the string interner.

The job of a backend is to actually store, manage and organize the interned strings. Different backends have different trade-offs. Users should pick their backend with hinsight of their personal use-case.

Required Associated Types§

Source

type Symbol: Symbol

The symbol used by the string interner backend.

Source

type Iter<'a>: Iterator<Item = (Self::Symbol, &'a str)> where Self: 'a

The iterator over the symbols and their strings.

Required Methods§

Source

fn with_capacity(cap: usize) -> Self

Creates a new backend for the given capacity.

The capacity denotes how many strings are expected to be interned.

Source

fn intern(&mut self, string: &str) -> Self::Symbol

Interns the given string and returns its interned ref and symbol.

§Note

The backend must make sure that the returned symbol maps back to the original string in its resolve method.

Source

fn shrink_to_fit(&mut self)

Shrink backend capacity to fit interned symbols exactly.

Source

fn resolve(&self, symbol: Self::Symbol) -> Option<&str>

Resolves the given symbol to its original string contents.

Source

unsafe fn resolve_unchecked(&self, symbol: Self::Symbol) -> &str

Resolves the given symbol to its original string contents.

§Safety

Does not perform validity checks on the given symbol and relies on the caller to be provided with a symbol that has been generated by the intern or intern_static methods of the same interner backend.

Source

fn iter(&self) -> Self::Iter<'_>

Creates an iterator that yields all interned strings and their symbols.

Provided Methods§

Source

fn intern_static(&mut self, string: &'static str) -> Self::Symbol

Interns the given static string and returns its interned ref and symbol.

§Note

The backend must make sure that the returned symbol maps back to the original string in its resolve method.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S> Backend for BucketBackend<S>
where S: Symbol,

Source§

type Symbol = S

Source§

type Iter<'a> = Iter<'a, S> where Self: 'a

Source§

impl<S> Backend for BufferBackend<S>
where S: Symbol,

Source§

type Symbol = S

Source§

type Iter<'a> = Iter<'a, S> where Self: 'a

Source§

impl<S> Backend for StringBackend<S>
where S: Symbol,

Source§

type Symbol = S

Source§

type Iter<'a> = Iter<'a, S> where Self: 'a