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§
sourcetype GlobalState: CustomGlobalState
type GlobalState: CustomGlobalState
The type of the thread-global extension to the runtime state.
sourcetype LocalState: CustomLocalState
type LocalState: CustomLocalState
The type of the thread-local extension to the runtime state.
Required Methods§
sourcefn store_state(
this: &Arc<RwLock<Self>>,
state: RunState<Self::GlobalState>,
) -> Result<(), VmError>
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.
sourcefn load_state(
this: &Arc<RwLock<Self>>,
) -> Result<RunState<Self::GlobalState>, VmError>
fn load_state( this: &Arc<RwLock<Self>>, ) -> Result<RunState<Self::GlobalState>, VmError>
Provided Methods§
sourcefn new_state(custom: Self::GlobalState) -> RunState<Self::GlobalState>
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.
sourcefn 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,
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.