Trait artichoke_backend::prelude::Intern[][src]

pub trait Intern {
    type Symbol: Copy;
    type Error;

    const SYMBOL_RANGE_START: Self::Symbol;

    fn intern_bytes<T>(
        &mut self,
        symbol: T
    ) -> Result<Self::Symbol, Self::Error>
    where
        T: Into<Cow<'static, [u8]>>
;
fn check_interned_bytes(
        &self,
        symbol: &[u8]
    ) -> Result<Option<Self::Symbol>, Self::Error>;
fn lookup_symbol(
        &self,
        symbol: Self::Symbol
    ) -> Result<Option<&[u8]>, Self::Error>;
fn symbol_count(&self) -> usize; fn intern_string<T>(
        &mut self,
        symbol: T
    ) -> Result<Self::Symbol, Self::Error>
    where
        T: Into<Cow<'static, str>>
, { ... }
fn check_interned_string(
        &self,
        symbol: &str
    ) -> Result<Option<Self::Symbol>, Self::Error> { ... } }

Store and retrieve bytestrings that have the same lifetime as the interpreter.

See the Ruby Symbol type.

Associated Types

type Symbol: Copy[src]

Concrete type for symbol identifiers.

The symbol identifier enables lookups in the underlying storage.

type Error[src]

Concrete type for errors returned while interning symbols.

Loading content...

Associated Constants

const SYMBOL_RANGE_START: Self::Symbol[src]

The initial Symbol index returned by the interner.

Implementing Intern requires that symbol identifiers form an arithmetic progression with a common difference of 1. The sequence of symbol identifiers must be representable by a Range<u32>.

Loading content...

Required methods

fn intern_bytes<T>(&mut self, symbol: T) -> Result<Self::Symbol, Self::Error> where
    T: Into<Cow<'static, [u8]>>, 
[src]

Store an immutable bytestring for the life of the interpreter.

Returns an identifier that enables retrieving the original bytes.

Errors

If the symbol store cannot be accessed, an error is returned.

If the symbol table overflows, an error is returned.

fn check_interned_bytes(
    &self,
    symbol: &[u8]
) -> Result<Option<Self::Symbol>, Self::Error>
[src]

Check if a bytestring is already interned and return its symbol identifier. Return None if the string has not been interned before.

Returns an identifier that enables retrieving the original bytes.

Errors

If the symbol store cannot be accessed, an error is returned.

fn lookup_symbol(
    &self,
    symbol: Self::Symbol
) -> Result<Option<&[u8]>, Self::Error>
[src]

Retrieve the original byte content of an interned bytestring.

Returns None if the symbol identifier is invalid.

Errors

If the symbol store cannot be accessed, an error is returned.

fn symbol_count(&self) -> usize[src]

Retrieve the number of unique strings interned.

This method should return the length of the underlying symbol table.

Loading content...

Provided methods

fn intern_string<T>(&mut self, symbol: T) -> Result<Self::Symbol, Self::Error> where
    T: Into<Cow<'static, str>>, 
[src]

Store an immutable string for the life of the interpreter.

Returns an identifier that enables retrieving the original bytes.

By default, this method is implemented by delegating to Intern::intern_bytes.

Errors

If the symbol store cannot be accessed, an error is returned.

If the symbol table overflows, an error is returned.

fn check_interned_string(
    &self,
    symbol: &str
) -> Result<Option<Self::Symbol>, Self::Error>
[src]

Check if a string is already interned and return its symbol identifier. Return None if the string has not been interned before.

Returns an identifier that enables retrieving the original bytes.

By default, this method is implemented by delegating to Intern::check_interned_bytes.

Errors

If the symbol store cannot be accessed, an error is returned.

Loading content...

Implementors

impl Intern for Artichoke[src]

type Symbol = u32

type Error = Error

const SYMBOL_RANGE_START: Self::Symbol[src]

fn intern_bytes<T>(&mut self, bytes: T) -> Result<Self::Symbol, Self::Error> where
    T: Into<Cow<'static, [u8]>>, 
[src]

fn check_interned_bytes(
    &self,
    bytes: &[u8]
) -> Result<Option<Self::Symbol>, Self::Error>
[src]

fn lookup_symbol(
    &self,
    symbol: Self::Symbol
) -> Result<Option<&[u8]>, Self::Error>
[src]

fn symbol_count(&self) -> usize[src]

Loading content...