Module texlang::vm::serde

source ·
Expand description

Serialization and deserialization of VMs

Texlang VMs can be serialized using the standard serde infrastructure because they always satisfy the ::serde::Serialize trait.

In the case when the VM’s state type implements super::HasDefaultBuiltInCommands, the VM satisfies the ::serde::Deserialize trait too.

If the state type doesn’t implement this trait, deserialization is slightly more complicated because the set of built-in commands needs to be provided at deserialization time. This is because the built-in commands which are regular Rust functions, and it is not possible to fully serialize and deserialize Rust functions. Deserialization of VMs is thus a two-step process:

  1. Deserialize the bytes to a DeserializedVM type.

  2. Invoke finish_deserialization with the deserialized VM and a map of built-in commands in order to recover the regular Texlang VM.

The Texlang VM has a deserialize_with_built_in_commands convenience method which performs both of these steps at once. In the case when VM’s state type implements super::HasDefaultBuiltInCommands, the VM’s implementation of ::serde::Deserialize handles all this automatically.

Structs

Functions