Skip to main content

StringInternerTrait

Trait StringInternerTrait 

Source
pub trait StringInternerTrait {
    type Symbol: Clone + Eq + Hash + Debug;

    // Required methods
    fn intern(&mut self, s: &str) -> Self::Symbol;
    fn resolve(&self, symbol: &Self::Symbol) -> String;
}
Expand description

A trait for abstracting string interning operations.

This trait allows for benchmarking different string interning strategies by providing a common interface for interning and resolving strings.

Required Associated Types§

Source

type Symbol: Clone + Eq + Hash + Debug

The type representing an interned string symbol or reference.

For no interning, this could be String itself or Arc<String>. For the string-interner crate, this would be its Symbol type.

Required Methods§

Source

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

Interns a string slice and returns its symbolic representation.

§Arguments
  • s - The string slice to intern.
§Returns

The interned representation of the string.

Source

fn resolve(&self, symbol: &Self::Symbol) -> String

Resolves an interned symbol back to its original string value.

This method is crucial for verifying correctness and for certain interning patterns, although not all “no interning” strategies would strictly need it for performance benchmarks.

§Arguments
  • symbol - The interned symbol or reference to resolve.
§Returns

An owned String containing the original value corresponding to the symbol.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§