Struct wasmtime::Engine

source ·
pub struct Engine { /* private fields */ }
Expand description

An Engine which is a global context for compilation and management of wasm modules.

An engine can be safely shared across threads and is a cheap cloneable handle to the actual engine. The engine itself will be deallocated once all references to it have gone away.

Engines store global configuration preferences such as compilation settings, enabled features, etc. You’ll likely only need at most one of these for a program.

Engines and Clone

Using clone on an Engine is a cheap operation. It will not create an entirely new engine, but rather just a new reference to the existing engine. In other words it’s a shallow copy, not a deep copy.

Engines and Default

You can create an engine with default configuration settings using Engine::default(). Be sure to consult the documentation of Config for default settings.

Implementations§

source§

impl Engine

source

pub fn new(config: &Config) -> Result<Engine>

Creates a new Engine with the specified compilation and configuration settings.

Errors

This method can fail if the config is invalid or some configurations are incompatible.

For example, feature reference_types will need to set the compiler setting enable_safepoints and unwind_info to true, but explicitly disable these two compiler settings will cause errors.

source

pub fn tls_eager_initialize()

Eagerly initialize thread-local functionality shared by all Engines.

Wasmtime’s implementation on some platforms may involve per-thread setup that needs to happen whenever WebAssembly is invoked. This setup can take on the order of a few hundred microseconds, whereas the overhead of calling WebAssembly is otherwise on the order of a few nanoseconds. This setup cost is paid once per-OS-thread. If your application is sensitive to the latencies of WebAssembly function calls, even those that happen first on a thread, then this function can be used to improve the consistency of each call into WebAssembly by explicitly frontloading the cost of the one-time setup per-thread.

Note that this function is not required to be called in any embedding. Wasmtime will automatically initialize thread-local-state as necessary on calls into WebAssembly. This is provided for use cases where the latency of WebAssembly calls are extra-important, which is not necessarily true of all embeddings.

source

pub fn config(&self) -> &Config

Returns the configuration settings that this engine is using.

source

pub fn same(a: &Engine, b: &Engine) -> bool

Returns whether the engine a and b refer to the same configuration.

source

pub fn increment_epoch(&self)

Increments the epoch.

When using epoch-based interruption, currently-executing Wasm code within this engine will trap or yield “soon” when the epoch deadline is reached or exceeded. (The configuration, and the deadline, are set on the Store.) The intent of the design is for this method to be called by the embedder at some regular cadence, for example by a thread that wakes up at some interval, or by a signal handler.

See Config::epoch_interruption for an introduction to epoch-based interruption and pointers to the other relevant methods.

Signal Safety

This method is signal-safe: it does not make any syscalls, and performs only an atomic increment to the epoch value in memory.

source

pub fn precompile_module(&self, bytes: &[u8]) -> Result<Vec<u8>>

Ahead-of-time (AOT) compiles a WebAssembly module.

The bytes provided must be in one of two formats:

  • A binary-encoded WebAssembly module. This is always supported.
  • A text-encoded instance of the WebAssembly text format. This is only supported when the wat feature of this crate is enabled. If this is supplied then the text format will be parsed before validation. Note that the wat feature is enabled by default.

This method may be used to compile a module for use with a different target host. The output of this method may be used with Module::deserialize on hosts compatible with the Config associated with this Engine.

The output of this method is safe to send to another host machine for later execution. As the output is already a compiled module, translation and code generation will be skipped and this will improve the performance of constructing a Module from the output of this method.

Trait Implementations§

source§

impl Clone for Engine

source§

fn clone(&self) -> Engine

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Engine

source§

fn default() -> Engine

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Engine

§

impl Send for Engine

§

impl Sync for Engine

§

impl Unpin for Engine

§

impl !UnwindSafe for Engine

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V