Skip to main content

Interner

Struct Interner 

Source
pub struct Interner { /* private fields */ }
Expand description

The table of names for one run. Thread-safe; share it with an Arc.

Tokens are assigned in insertion order, starting at 0. To reproduce TLC’s order of strings, model values and record fields, intern names in the order SANY and TLC first meet them.

use dive_value::Interner;
let names = Interner::new();
let b = names.intern("b");
let a = names.intern("a");
assert!(b.tok() < a.tok());
assert_eq!(names.intern("b"), b);

Implementations§

Source§

impl Interner

Source

pub fn new() -> Self

An empty table.

Source

pub fn intern(&self, text: &str) -> Atom

Returns the atom for text, interning it with the next token if it is new.

Source

pub fn resolve(&self, tok: u32) -> Option<Atom>

Returns the atom with token tok, if one has been interned.

This is the inverse of Atom::tok for this table. State encodings store names by token (crate::codec), and decoding resolves them here.

use dive_value::Interner;
let names = Interner::new();
let a = names.intern("a");
assert_eq!(names.resolve(a.tok()), Some(a));
assert_eq!(names.resolve(7), None);
Source

pub fn get(&self, text: &str) -> Option<Atom>

Returns the atom for text if it has been interned.

Source

pub fn len(&self) -> usize

The number of interned names.

Source

pub fn is_empty(&self) -> bool

Whether no name has been interned.

Trait Implementations§

Source§

impl Debug for Interner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Interner

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.