pub enum Variable<S> {
    Int(TypedVariable<S, i32>),
    CatCode(TypedVariable<S, CatCode>),
    MathCode(TypedVariable<S, MathCode>),
    TokenList(TypedVariable<S, Vec<Token>>),
}
Expand description

TeX variable of any type.

A variable uniquely identifies a Rust value in the state, like an i32. Operations on this value (like reading or setting the value) can be done in two ways:

  1. (Easy, less flexible) Use the methods directly on this type like Variable::value to read the value. These methods are really ergonomic. The problem with the value method specifically is that the result is a reference which keeps the borrow of the state alive. Thus, while holding onto the result of the value, you can’t do anything this the input stream like reading an argument. This is especially a problem when you need to perform a different action depending on the concrete type of the variable.

  2. (Trickier, more flexible) Match on the type’s enum variants to determine the concrete type of the variable. The TypedVariable value obtained in this way can be used to perform operations on the value. The main benefit of this approach is that after matching on the type, you can still use the input stream to do things because there is not borrow alive.

Variants§

Implementations§

source§

impl<S: TexlangState> Variable<S>

source

pub fn value<'a>(&self, state: &'a S) -> ValueRef<'a>

Return a reference to the value of the variable.

Trait Implementations§

source§

impl<S: TexlangState> Parsable<S> for Variable<S>

source§

fn parse_impl(input: &mut ExpandedStream<S>) -> Result<Self, Box<Error>>

Parses a value from the vm::ExpandedStream.
source§

fn parse<I>(input: &mut I) -> Result<Self, Box<Error>>where I: AsMut<ExpandedStream<S>>,

Parses a value from an input stream. Read more

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for Variable<S>

§

impl<S> Send for Variable<S>

§

impl<S> Sync for Variable<S>

§

impl<S> Unpin for Variable<S>

§

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