Trait brane_exe::vm::Vm

source ·
pub trait Vm {
    type GlobalState: CustomGlobalState;
    type LocalState: CustomLocalState;

    // Required methods
    fn store_state(
        this: &Arc<RwLock<Self>>,
        state: RunState<Self::GlobalState>,
    ) -> Result<(), VmError>;
    fn load_state(
        this: &Arc<RwLock<Self>>,
    ) -> Result<RunState<Self::GlobalState>, VmError>;

    // Provided methods
    fn new_state(custom: Self::GlobalState) -> RunState<Self::GlobalState> { ... }
    fn run<'life0, 'async_trait, P>(
        this: Arc<RwLock<Self>>,
        snippet: Workflow,
        prof: ProfileScopeHandle<'life0>,
    ) -> Pin<Box<dyn Future<Output = Result<FullValue, VmError>> + Send + 'async_trait>>
       where Self: Sync + Send + 'async_trait,
             P: 'async_trait + VmPlugin<GlobalState = Self::GlobalState, LocalState = Self::LocalState>,
             'life0: 'async_trait { ... }
}
Expand description

Defines a common interface (and some code) for virtual machines.

Required Associated Types§

source

type GlobalState: CustomGlobalState

The type of the thread-global extension to the runtime state.

source

type LocalState: CustomLocalState

The type of the thread-local extension to the runtime state.

Required Methods§

source

fn store_state( this: &Arc<RwLock<Self>>, state: RunState<Self::GlobalState>, ) -> Result<(), VmError>

A function that stores the given runtime state information in the parent struct.

This is important and will be used later.

§Arguments
  • state: The current state of the workflow we have executed.
§Returns

Nothing, but should change the internals to return this state later upon request.

§Errors

This function may error for its own reasons.

source

fn load_state( this: &Arc<RwLock<Self>>, ) -> Result<RunState<Self::GlobalState>, VmError>

A function that returns the VM’s runtime state in the parent struct.

This is important and will be used later.

§Returns

The RunState of this application if it exists, or else None.

§Errors

This function may error for its own reasons.

Provided Methods§

source

fn new_state(custom: Self::GlobalState) -> RunState<Self::GlobalState>

Initializes a new global state based on the given custom part.

§Arguments
  • pindex: The package index which we can use for resolving packages.
  • dindex: The data index which we can use for resolving datasets.
  • custom: The custom part of the global state with which we will initialize it.
§Returns

A new RunState instance.

source

fn run<'life0, 'async_trait, P>( this: Arc<RwLock<Self>>, snippet: Workflow, prof: ProfileScopeHandle<'life0>, ) -> Pin<Box<dyn Future<Output = Result<FullValue, VmError>> + Send + 'async_trait>>
where Self: Sync + Send + 'async_trait, P: 'async_trait + VmPlugin<GlobalState = Self::GlobalState, LocalState = Self::LocalState>, 'life0: 'async_trait,

Runs the given workflow, possibly asynchronously (if a parallel is encountered / there are external functions calls and the given closure runs this asynchronously.)

§Generic arguments
  • P: The “VM plugin” that will fill in the blanks with respect to interacting with the outside world.
§Arguments
  • snippet: The snippet to compile. This is either the entire workflow, or a snippet of it. In the case of the latter, the internal state will be used (and updated).
  • prof: The ProfileScope that can be used to provide additional information about the timings of the VM (framework-wise, not user-wise).
§Returns

The result if the Workflow returned any.

Object Safety§

This trait is not object safe.

Implementors§