Struct texlang::variable::Command

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

A TeX variable command.

Variable commands are resolved to obtain a Variable.

A command consists of three parts.

The first two parts are an immutable getter (of type RefFn) and a mutable getter (of type MutRefFn). Both of these getters accept a reference to the state (where the variable’s value lives) and an Index. The index can be used by the getters to return different values in memory. For example, if the getters read from an array, the index may be just the index in the array. This mechanism allows users of Texlang to write one pair of getters that can be used in many variables.

The third part of a command is an IndexResolver that is used to determine the aforementioned index of a variable at runtime. The process of resolving a command involves determining the Index and returning a Variable type, which under the hood is just the two getters and this index.

Implementations§

source§

impl<S> Command<S>

source

pub fn new_singleton<T: SupportedType>( ref_fn: RefFn<S, T>, ref_mut_fn: MutRefFn<S, T> ) -> Command<S>

Create a new variable command.

source

pub fn new_array<T: SupportedType>( ref_fn: RefFn<S, T>, ref_mut_fn: MutRefFn<S, T>, index_resolver: IndexResolver<S> ) -> Command<S>

Create a new variable command.

source

pub fn new_getter_provider<T: SupportedType>( ref_fn: RefFn<S, T>, ref_mut_fn: MutRefFn<S, T> ) -> Command<S>

Create a new getter provider.

A getter provider is a variable command that is not intended to be invoked directly - in fact, the variable command will panic the program if it is invoked. Instead the provider is included in a VM’s initial commands so that the VM has a reference to the getters inside the command. If a variable with the same getters is subsequently inserted into the commands map (for example, by a \countdef type command), the VM can still serialize that variable using the getters provided here.

source§

impl<S: TexlangState> Command<S>

source

pub fn resolve( &self, token: Token, input: &mut ExpandedStream<S> ) -> Result<Variable<S>, Box<Error>>

Resolve the command to obtain a Variable.

source§

impl<S: TexlangState> Command<S>

source

pub fn value<'a>( &self, token: Token, input: &'a mut ExpandedStream<S> ) -> Result<ValueRef<'a>, Box<Error>>

Resolve the command to a variable and return the value of the variable.

Trait Implementations§

source§

impl<S> From<Command<S>> for BuiltIn<S>

source§

fn from(cmd: Command<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for Command<S>

§

impl<S> Send for Command<S>

§

impl<S> Sync for Command<S>

§

impl<S> Unpin for Command<S>

§

impl<S> UnwindSafe for Command<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.