string_interner

Trait Symbol

Source
pub trait Symbol: Copy + Eq {
    // Required methods
    fn try_from_usize(index: usize) -> Option<Self>;
    fn to_usize(self) -> usize;
}
Expand description

Types implementing this trait can be used as symbols for string interners.

The StringInterner::get_or_intern method returns Symbol types that allow to look-up the original string using StringInterner::resolve.

§Note

Optimal symbols allow for efficient comparisons and have a small memory footprint.

Required Methods§

Source

fn try_from_usize(index: usize) -> Option<Self>

Creates a symbol from a usize.

Returns None if index is out of bounds for the symbol.

Source

fn to_usize(self) -> usize

Returns the usize representation of self.

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.

Implementations on Foreign Types§

Source§

impl Symbol for usize

Implementors§