Struct ion_rs::SymbolTable

source ·
pub struct SymbolTable { /* private fields */ }
Expand description

Stores mappings from Symbol IDs to text and vice-versa.

Implementations§

source§

impl SymbolTable

source

pub fn new() -> SymbolTable

Constructs a new symbol table pre-populated with the system symbols defined in the spec.

source

pub fn reset(&mut self)

source

pub fn intern<A: AsRef<str>>(&mut self, text: A) -> SymbolId

If text is already in the symbol table, returns the corresponding SymbolId. Otherwise, adds text to the symbol table and returns the newly assigned SymbolId.

source

pub fn add_placeholder(&mut self) -> SymbolId

Assigns unknown text to the next available symbol ID. This is used when an Ion reader encounters null or non-string values in a stream’s symbol table.

source

pub fn intern_or_add_placeholder<A: AsRef<str>>( &mut self, maybe_text: Option<A> ) -> SymbolId

If maybe_text is Some(text), this method is equivalent to intern(text). If maybe_text is None, this method is equivalent to add_placeholder().

source

pub fn sid_for<A: AsRef<str>>(&self, text: &A) -> Option<SymbolId>

If defined, returns the Symbol ID associated with the provided text.

source

pub fn text_for(&self, sid: SymbolId) -> Option<&str>

If defined, returns the text associated with the provided Symbol ID.

source

pub fn symbol_for(&self, sid: SymbolId) -> Option<&Symbol>

If defined, returns the Symbol associated with the provided Symbol ID.

source

pub fn sid_is_valid(&self, sid: SymbolId) -> bool

Returns true if the provided symbol ID maps to an entry in the symbol table (i.e. it is in the range of known symbols: 0 to max_id)

Note that a symbol ID can be valid but map to unknown text. If a symbol table contains a null or non-string value, that entry in the table will be defined but not have text associated with it.

This method allows users to distinguish between a SID with unknown text and a SID that is invalid.

source

pub fn symbols(&self) -> &[Symbol]

Returns a slice of references to the symbol text stored in the table.

The symbol table can contain symbols with unknown text; see the documentation for Symbol for more information.

source

pub fn symbols_tail(&self, start: usize) -> &[Symbol]

Returns a slice of references to the symbol text stored in the table starting at the given symbol ID. If a symbol table append occurs during reading, this function can be used to easily view the new symbols that has been added to the table.

The symbol table can contain symbols with unknown text; see the documentation for Symbol for more information.

source

pub fn len(&self) -> usize

Returns the number of symbols defined in the table.

Trait Implementations§

source§

impl Default for SymbolTable

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.