Struct texlang::vm::VM

source ·
pub struct VM<S> {
    pub state: S,
    pub commands_map: Map<S>,
    pub working_directory: Option<PathBuf>,
    /* private fields */
}
Expand description

The Texlang virtual machine.

Fields§

§state: S

The state

§commands_map: Map<S>

The commands map

§working_directory: Option<PathBuf>

The working directory which is used as the root for relative file paths

This is None if the working directory could not be determined.

Implementations§

source§

impl<S: TexlangState> VM<S>

source

pub fn run<H: Handlers<S>>(&mut self) -> Result<(), Box<Error>>

Run the VM.

It is assumed that the VM has been preloaded with TeX source code using the VM::push_source method.

source§

impl<S: Default> VM<S>

source

pub fn new_with_built_in_commands( built_in_commands: HashMap<&str, BuiltIn<S>> ) -> VM<S>

Create a new VM with the provided built-in commands.

If the state type satisfies the HasDefaultBuiltInCommands trait, and you are using the default built-ins, use the VM::new method instead.

source§

impl<S: Default + HasDefaultBuiltInCommands> VM<S>

source

pub fn new() -> VM<S>

Create a new VM.

source§

impl<'de, S: Deserialize<'de>> VM<S>

Deserialize a Texlang VM using the provided built-in commands.

If the state type satisfies the HasDefaultBuiltInCommands trait, and you are deserializing using the default built-ins, you don’t need to use this function. You can use the serde deserialize trait directly. See the serde submodule for more information on deserialization.

source

pub fn deserialize_with_built_in_commands<D: Deserializer<'de>>( deserializer: D, built_in_commands: HashMap<&str, BuiltIn<S>> ) -> Result<Self, D::Error>

source§

impl<S: TexlangState> VM<S>

source

pub fn push_source<T1: Into<PathBuf>, T2: Into<String>>( &mut self, file_name: T1, source_code: T2 ) -> Result<(), Box<Error>>

Add new source code to the VM.

TeX input source code is organized as a stack. Pushing source code onto the stack will mean it is executed first.

source§

impl<S> VM<S>

source

pub fn clear_sources(&mut self)

Clear all source code from the VM.

source

pub fn get_commands_as_map_slow(&self) -> HashMap<String, BuiltIn<S>>

Return a regular hash map with all the commands as they are currently defined.

This function is extremely slow and is only intended to be invoked on error paths.

source

pub fn cs_name_interner(&self) -> &CsNameInterner

Return a reference to the control sequence name string interner.

This interner can be used to resolve CsName types into regular strings.

source

pub fn trace(&self, token: Token) -> SourceCodeTrace

source

pub fn trace_end_of_input(&self) -> SourceCodeTrace

source

pub fn num_current_sources(&self) -> usize

Returns the number of current sources on the source stack

Trait Implementations§

source§

impl<S: Default + HasDefaultBuiltInCommands> Default for VM<S>

source§

fn default() -> Self

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

impl<'de, S: Deserialize<'de> + HasDefaultBuiltInCommands> Deserialize<'de> for VM<S>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<State: Serialize> Serialize for VM<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 VM<S>

§

impl<S> !Send for VM<S>

§

impl<S> !Sync for VM<S>

§

impl<S> Unpin for VM<S>where S: Unpin,

§

impl<S> UnwindSafe for VM<S>where S: UnwindSafe,

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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,