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)

Lifetimes

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.

Example

use sandkiste::prelude::*;

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

Required Associated Types

Data type representing values passed to or returned from machine

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

Implementors