pub struct WasmEngine { /* private fields */ }Expand description
Sandbox-aware wrapper around a Wasmtime [Engine].
Configures the engine for fuel-metered execution and compiles/instantiates modules according
to the associated SandboxPolicy.
Implementations§
Source§impl WasmEngine
impl WasmEngine
Sourcepub fn new(policy: SandboxPolicy) -> Result<Self>
pub fn new(policy: SandboxPolicy) -> Result<Self>
Builds a WasmEngine with fuel metering enabled and Cranelift optimizations for speed.
The returned engine is ready to compile modules; per-guest limits come from policy when
calling create_store and create_bounded_memory.
Sourcepub fn engine(&self) -> &Engine
pub fn engine(&self) -> &Engine
Returns the underlying Wasmtime [Engine] for compilation and linking.
Sourcepub fn policy(&self) -> &SandboxPolicy
pub fn policy(&self) -> &SandboxPolicy
Returns the active SandboxPolicy (memory cap, fuel, and capability flags).
Sourcepub fn create_store<T>(&self, data: T) -> Result<Store<T>>
pub fn create_store<T>(&self, data: T) -> Result<Store<T>>
Creates a new [Store] with data as host state and sets fuel to policy.fuel_limit.
Sourcepub fn create_bounded_memory(
&self,
store: &mut Store<impl Send>,
) -> Result<Memory>
pub fn create_bounded_memory( &self, store: &mut Store<impl Send>, ) -> Result<Memory>
Allocates a new linear [Memory] with minimum 1 page and maximum policy.max_memory_pages.
Sourcepub fn compile_module(&self, wasm_bytes: &[u8]) -> Result<Module>
pub fn compile_module(&self, wasm_bytes: &[u8]) -> Result<Module>
Compiles raw Wasm bytes into a [Module] using this engine’s configuration.
Auto Trait Implementations§
impl Freeze for WasmEngine
impl !RefUnwindSafe for WasmEngine
impl Send for WasmEngine
impl Sync for WasmEngine
impl Unpin for WasmEngine
impl UnsafeUnpin for WasmEngine
impl !UnwindSafe for WasmEngine
Blanket Implementations§
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§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