Trait sandkiste::Machine

source ·
pub trait Machine<'a> {
    type Datum<'b, 'c>
       where Self: 'b;
    type Function<'b>: for<'c> Function<Datum<'c> = Self::Datum<'b, 'c>>
       where Self: 'b;
Expand description

Virtual machine to execute code (with inner mutability)


The lifetime argument 'a is a lower bound for closures passed to the machine (see Callback), which will usually be inferred automatically.

The generic associated types have a lifetime argument 'b, which is usually equal to the lifetime of the shared reference to the machine that is being worked with. The lifetime argument 'c of Machine::Datum is usually 'static but may be shorter for temporary values that have been created from a &str, for example.


use sandkiste::prelude::*;

fn say_hello<'a, 'b, M, C>(
    machine: &'b M,
    code: C,
) -> Result<String, MachineError>
    M: Machine<'a> + Compile<'a, C>,
    for<'c> <M as Machine<'a>>::Datum<'b, 'c>: MaybeString<'c>,
        .compile(None, code)?
        .call_1ret(["Hi there! Who are you?".into()])?

Required Associated Types§


type Datum<'b, 'c> where Self: 'b

Data type representing values passed to or returned from machine


type Function<'b>: for<'c> Function<Datum<'c> = Self::Datum<'b, 'c>> where Self: 'b

Function (for example returned by Compile::compile) which can be executed by the machine