Struct Engine
pub struct Engine {
inner: Arc<Mutex<EngineInner>>,
target: Arc<Target>,
engine_id: EngineId,
tunables: Arc<dyn Tunables + Sync + Send>,
name: String,
}Expand description
A WebAssembly Universal Engine.
Fields§
§inner: Arc<Mutex<EngineInner>>§target: Arc<Target>§engine_id: EngineId§tunables: Arc<dyn Tunables + Sync + Send>§name: StringImplementations§
§impl Engine
impl Engine
pub fn new(
compiler_config: Box<dyn CompilerConfig>,
target: Target,
features: Features,
) -> Engine
pub fn new( compiler_config: Box<dyn CompilerConfig>, target: Target, features: Features, ) -> Engine
Create a new Engine with the given config
pub fn deterministic_id(&self) -> String
pub fn deterministic_id(&self) -> String
Returns the deterministic id of this engine
pub fn headless() -> Engine
pub fn headless() -> Engine
Create a headless Engine
A headless engine is an engine without any compiler attached. This is useful for assuring a minimal runtime for running WebAssembly modules.
For example, for running in IoT devices where compilers are very expensive, or also to optimize startup speed.
§Important
Headless engines can’t compile or validate any modules,
they just take already processed Modules (via Module::serialize).
pub fn inner(&self) -> MutexGuard<'_, EngineInner>
pub fn inner(&self) -> MutexGuard<'_, EngineInner>
Get reference to EngineInner.
pub fn inner_mut(&self) -> MutexGuard<'_, EngineInner>
pub fn inner_mut(&self) -> MutexGuard<'_, EngineInner>
Get mutable reference to EngineInner.
pub fn register_signature(
&self,
func_type: &FunctionType,
) -> VMSharedSignatureIndex
pub fn register_signature( &self, func_type: &FunctionType, ) -> VMSharedSignatureIndex
Register a signature
pub fn lookup_signature(
&self,
sig: VMSharedSignatureIndex,
) -> Option<FunctionType>
pub fn lookup_signature( &self, sig: VMSharedSignatureIndex, ) -> Option<FunctionType>
Lookup a signature
pub fn validate(&self, binary: &[u8]) -> Result<(), CompileError>
pub fn validate(&self, binary: &[u8]) -> Result<(), CompileError>
Validates a WebAssembly module
pub fn compile(&self, binary: &[u8]) -> Result<Arc<Artifact>, CompileError>
pub fn compile(&self, binary: &[u8]) -> Result<Arc<Artifact>, CompileError>
Compile a WebAssembly binary
pub fn compile_with_progress(
&self,
binary: &[u8],
progress_callback: Option<CompilationProgressCallback>,
) -> Result<Arc<Artifact>, CompileError>
pub fn compile_with_progress( &self, binary: &[u8], progress_callback: Option<CompilationProgressCallback>, ) -> Result<Arc<Artifact>, CompileError>
Compile a WebAssembly binary with a progress callback.
pub unsafe fn deserialize_unchecked(
&self,
bytes: OwnedBuffer,
) -> Result<Arc<Artifact>, DeserializeError>
pub unsafe fn deserialize_unchecked( &self, bytes: OwnedBuffer, ) -> Result<Arc<Artifact>, DeserializeError>
Deserializes a WebAssembly module which was previously serialized with
[wasmer::Module::serialize].
§Safety
pub unsafe fn deserialize(
&self,
bytes: OwnedBuffer,
) -> Result<Arc<Artifact>, DeserializeError>
pub unsafe fn deserialize( &self, bytes: OwnedBuffer, ) -> Result<Arc<Artifact>, DeserializeError>
Deserializes a WebAssembly module which was previously serialized with
[wasmer::Module::serialize].
§Safety
pub unsafe fn deserialize_from_file(
&self,
file_ref: &Path,
) -> Result<Arc<Artifact>, DeserializeError>
pub unsafe fn deserialize_from_file( &self, file_ref: &Path, ) -> Result<Arc<Artifact>, DeserializeError>
pub unsafe fn deserialize_from_file_unchecked(
&self,
file_ref: &Path,
) -> Result<Arc<Artifact>, DeserializeError>
pub unsafe fn deserialize_from_file_unchecked( &self, file_ref: &Path, ) -> Result<Arc<Artifact>, DeserializeError>
pub fn id(&self) -> &EngineId
pub fn id(&self) -> &EngineId
A unique identifier for this object.
This exists to allow us to compare two Engines for equality. Otherwise, comparing two trait objects unsafely relies on implementation details of trait representation.
pub fn set_tunables(&mut self, tunables: impl Tunables + Send + Sync + 'static)
pub fn set_tunables(&mut self, tunables: impl Tunables + Send + Sync + 'static)
Attach a Tunable to this engine
pub fn with_opts(
&mut self,
_suggested_opts: &UserCompilerOptimizations,
) -> Result<(), CompileError>
pub fn with_opts( &mut self, _suggested_opts: &UserCompilerOptimizations, ) -> Result<(), CompileError>
Add suggested optimizations to this engine.
§Note
Not every backend supports every optimization. This function may fail (i.e. not set the suggested optimizations) silently if the underlying engine backend does not support one or more optimizations.
Trait Implementations§
§impl From<Box<dyn CompilerConfig>> for Engine
impl From<Box<dyn CompilerConfig>> for Engine
§fn from(config: Box<dyn CompilerConfig>) -> Engine
fn from(config: Box<dyn CompilerConfig>) -> Engine
§impl From<EngineBuilder> for Engine
impl From<EngineBuilder> for Engine
§fn from(engine_builder: EngineBuilder) -> Engine
fn from(engine_builder: EngineBuilder) -> Engine
§impl From<Singlepass> for Engine
impl From<Singlepass> for Engine
§fn from(config: Singlepass) -> Engine
fn from(config: Singlepass) -> Engine
Auto Trait Implementations§
impl Freeze for Engine
impl !RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl !UnwindSafe for Engine
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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