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:
-
(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.
-
(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.