pub struct Store {
pub(crate) inner: Box<StoreInner>,
}Expand description
The store represents all global state that can be manipulated by WebAssembly programs. It consists of the runtime representation of all instances of functions, tables, memories, and globals that have been allocated during the lifetime of the abstract machine.
The Store is tied to the underlying Engine that is — among many things — used to
compile the Wasm bytes into a valid module artifact.
For more information, check out the [related WebAssembly specification] [related WebAssembly specification]: https://webassembly.github.io/spec/core/exec/runtime.html#store
Fields§
§inner: Box<StoreInner>Implementations§
Source§impl Store
impl Store
Sourcepub fn set_trap_handler(&mut self, handler: Option<Box<TrapHandlerFn<'static>>>)
pub fn set_trap_handler(&mut self, handler: Option<Box<TrapHandlerFn<'static>>>)
Set the TrapHandlerFn for this store.
§Note
Not every implementor allows changing the trap handler. In those store that don’t allow it, this function has no effect.
Sourcepub fn engine_mut(&mut self) -> &mut Engine
pub fn engine_mut(&mut self) -> &mut Engine
Returns mutable reference to Engine.
Sourcepub fn same(a: &Self, b: &Self) -> bool
pub fn same(a: &Self, b: &Self) -> bool
Checks whether two stores are identical. A store is considered equal to another store if both have the same engine.
Sourcepub fn with_current<R>(f: impl FnOnce(&mut StoreMut<'_>) -> R) -> Option<R>
pub fn with_current<R>(f: impl FnOnce(&mut StoreMut<'_>) -> R) -> Option<R>
Runs f with the store this thread is currently executing, if that
store has been lent out with StoreMut::parked.
Host code called from Wasm normally receives the store as a
FunctionEnvMut, but code the host in turn
calls into cannot always be handed one: an embedded engine invoking a
callback, a C library’s allocator hook, anything reached through frames
that carry no Rust references. This is how such code gets the store the
current call is running under, so it can use the ordinary store-taking
APIs — Memory::grow and friends — instead of
reaching around them.
Returns None unless a store is executing on this thread and every
borrow of it on this thread’s stack has been parked. Holding a
StoreMut and calling this would alias that borrow, so the answer
there is None rather than a second handle to the same store; parking
is what makes the outstanding borrow provably unreachable.
A store starts executing when a call enters it, which only the sys
backend tracks — so on the others this is None inside a host function.
StoreMut::parked works everywhere, though, so an embedder can always
lend a store it owns, whether or not a call is running.
Nothing guarantees the store is the one the caller expects — a thread
may run several — so check any handle before using it, with
Memory::is_from_store or by comparing
StoreObjects::id. Using a handle from another store panics.
Sourcepub fn interrupter(&self) -> Interrupter
pub fn interrupter(&self) -> Interrupter
Builds an Interrupter for this store. Calling Interrupter::interrupt
will cause running WASM code to terminate immediately with a
HostInterrupt trap.
Best effort is made to ensure interrupts are handled. However, there is no guarantee; under rare circumstances, it is possible for the interrupt to be missed. One such case is when the target thread is about to call WASM code but has not yet made the call.
To make sure the code is interrupted, the target thread should notify the signalling thread that it has finished running in some way, and the signalling thread must wait for that notification and retry the interrupt if the notification is not received after some time. Embedders are expected to implement this logic.
If an interrupt is delivered while an imported function is running, the interrupt will simply be stored and processed only when the imported function returns control to WASM code. No effort is made to interrupt running imported functions. Embedders are expected to implement support for interruption of long-running or blocking imported functions separately.
Sourcepub fn into_async(self) -> StoreAsync
pub fn into_async(self) -> StoreAsync
Transforms this store into a StoreAsync which can be used
to invoke Function::call_async.
Trait Implementations§
Source§impl AsEngineRef for Store
impl AsEngineRef for Store
Source§impl AsStoreMut for Store
impl AsStoreMut for Store
Source§fn as_store_mut(&mut self) -> StoreMut<'_>
fn as_store_mut(&mut self) -> StoreMut<'_>
StoreMut pointing to the underlying context.Source§fn objects_mut(&mut self) -> &mut StoreObjects
fn objects_mut(&mut self) -> &mut StoreObjects
Source§impl AsStoreRef for Store
impl AsStoreRef for Store
Source§fn as_store_ref(&self) -> StoreRef<'_>
fn as_store_ref(&self) -> StoreRef<'_>
StoreRef pointing to the underlying context.Source§fn as_store_async(&self) -> Option<impl AsStoreAsync + 'static>
fn as_store_async(&self) -> Option<impl AsStoreAsync + 'static>
StoreAsync if the current
context is asynchronous. The store will be locked since
it’s already active in the current context, but can be used
to spawn new coroutines via
Function::call_async.Auto Trait Implementations§
impl Freeze for Store
impl !RefUnwindSafe for Store
impl !Send for Store
impl !Sync for Store
impl Unpin for Store
impl UnsafeUnpin for Store
impl !UnwindSafe for Store
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more