Struct texlang::command::Map

source ·
pub struct Map<S> { /* private fields */ }
Expand description

Map is a map type where the keys are control sequence names and the values are TeX commands.

There are a number of design goals for the map:

  • Make retrieving the function for a command very fast. This is achieved primarily by storing command functions by themselves in an array. The index in the array is the control sequence name, which is an integer when interned. This implementation choice means fast-as-possible lookups. Storing the function by itself means there is good cache locality.

  • Insert built in commands at the start insert_built_in(cs_name, cmd),

  • Insert variable commands that aren’t there at the start, but will be in the future. E.g., \countdef register_built_in(cmd) <- must have a unique ID. Is type ID stable across binary builds? Maybe need to use a string ID instead? But then need to feed that the library using this registered

  • Should we enforce that the previous two steps can only be done at creation time? Probably Maybe initialize the map using Map<cs_name, cmd> and Vec<cmd>. Can provide cs_name<->str wrapper at the VM level

  • While running, insert macros insert_macro(&str, macro)

  • While running, alias commands by current name or using the special ID inserts alias_control_sequence(cs_name, cs_name) -> undefined control sequence error alias_registered_built_in(cs_name, cmd_id, variable_addr) alias_character(cs_name, token::Token)

Implementations§

source§

impl<S> Map<S>

source

pub fn get_command(&self, command_ref: &CommandRef) -> Option<&Command<S>>

source

pub fn get_tag(&self, command_ref: &CommandRef) -> Option<Tag>

source

pub fn built_in_commands(&self) -> &HashMap<CsName, BuiltIn<S>>

source

pub fn get_command_slow(&self, command_ref: &CommandRef) -> Option<BuiltIn<S>>

source

pub fn insert_variable_command( &mut self, command_ref: CommandRef, variable_command: Command<S>, scope: Scope )

source

pub fn insert_macro(&mut self, name: CommandRef, texmacro: Macro, scope: Scope)

source

pub fn alias_control_sequence( &mut self, alias: CommandRef, command: &CommandRef, scope: Scope ) -> Result<(), InvalidAlias>

source

pub fn alias_token(&mut self, alias: CommandRef, token: Token, scope: Scope)

source

pub fn insert( &mut self, command_ref: CommandRef, func: Command<S>, scope: Scope )

source

pub fn to_hash_map_slow(&self) -> HashMap<CsName, BuiltIn<S>>

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> usize

Trait Implementations§

source§

impl<State> Serialize for Map<State>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for Map<S>

§

impl<S> !Send for Map<S>

§

impl<S> !Sync for Map<S>

§

impl<S> Unpin for Map<S>

§

impl<S> UnwindSafe for Map<S>

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.