pub struct MultiUseContextCallback<'func, Cur: Sandbox, F>{ /* private fields */ }
Expand description
A TransitionMetadata
that calls a callback. The callback function takes
a mutable reference to a MultiUseGuestCallContext
and returns a Result<()>
to signify success or failure of the function.
The function use the context to call guest functions.
Construct one of these by passing your callback to
MultiUseContextCallback::from
, as in the following code (assuming MySandbox
is a Sandbox
implementation):
let my_cb_fn: dyn FnOnce(&mut MultiUseGuestCallContext) -> Result<()> = |_sbox| {
println!("hello world!");
};
let mutating_cb = MultiUseContextCallback::from(my_cb_fn);
Implementations§
Source§impl<Cur: Sandbox, F> MultiUseContextCallback<'_, Cur, F>
impl<Cur: Sandbox, F> MultiUseContextCallback<'_, Cur, F>
Sourcepub fn call(self, cur: &mut MultiUseGuestCallContext) -> Result<()>
pub fn call(self, cur: &mut MultiUseGuestCallContext) -> Result<()>
Invokes the callback on the provided guest context
Trait Implementations§
Source§impl<'a, F> EvolvableSandbox<MultiUseSandbox, MultiUseSandbox, MultiUseContextCallback<'a, MultiUseSandbox, F>> for MultiUseSandbox
impl<'a, F> EvolvableSandbox<MultiUseSandbox, MultiUseSandbox, MultiUseContextCallback<'a, MultiUseSandbox, F>> for MultiUseSandbox
Source§fn evolve(
self,
transition_func: MultiUseContextCallback<'a, MultiUseSandbox, F>,
) -> Result<MultiUseSandbox>
fn evolve( self, transition_func: MultiUseContextCallback<'a, MultiUseSandbox, F>, ) -> Result<MultiUseSandbox>
The purpose of this function is to allow multiple states to be associated with a single MultiUseSandbox.
An implementation such as HyperlightJs or HyperlightWasm can use this to call guest functions to load JS or WASM code and then evolve the sandbox causing state to be captured. The new MultiUseSandbox can then be used to call guest functions to execute the loaded code.
The evolve function creates a new MultiUseCallContext which is then passed to a callback function allowing the callback function to call guest functions as part of the evolve process, once the callback function is complete the context is finished using a crate internal method that does not restore the prior state of the Sandbox. It then creates a mew memory snapshot on the snapshot stack and returns the MultiUseSandbox