Skip to main content

Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

Runtime configuration for zwasm modules.

Allows fine-grained control over memory allocation, fuel, timeouts, and resource limits. Used to customize the execution environment for a Module.

Implementations§

Source§

impl Config

Source

pub fn new() -> Result<Self, ZwasmError>

Creates a new runtime configuration for zwasm modules.

Use this to control memory allocation, fuel, timeouts, and other resource limits.

Source

pub fn set_allocator<F, G>(&mut self, alloc_fn: F, free_fn: G)
where F: Fn(usize, usize) -> *mut c_void + Send + Sync + 'static, G: Fn(*mut c_void, usize, usize) + Send + Sync + 'static,

Sets custom memory allocation hooks for the zwasm runtime.

Allows you to override all memory allocation for Wasm execution. Useful for sandboxing or tracking allocations.

§Safety

The provided callbacks must obey allocator semantics for all (size, align) pairs that the runtime may request. Returning invalid pointers or violating alignment/ deallocation contracts can cause undefined behavior in native code.

Source

pub fn set_fuel(&mut self, fuel: u64)

Sets the execution fuel limit for the module.

Fuel limits restrict the number of instructions a module can execute before trapping.

Source

pub fn set_timeout(&mut self, timeout_ms: u64)

Sets the execution timeout (in milliseconds) for the module.

Execution will be interrupted if the timeout is exceeded.

Source

pub fn set_max_memory(&mut self, max_memory: u64)

Sets the maximum linear memory (in bytes) for the module.

Prevents Wasm modules from growing memory beyond this limit.

Source

pub fn set_force_interpreter(&mut self, force: bool)

Forces interpreter mode (disables JIT) when true.

Useful for debugging or running on unsupported platforms.

Source

pub fn set_cancelable(&mut self, cancelable: bool)

Enables or disables cancellation support for the module.

When enabled, execution can be cancelled via Module::cancel.

Trait Implementations§

Source§

impl Drop for Config

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Config

§

impl !Send for Config

§

impl !Sync for Config

§

impl !UnwindSafe for Config

§

impl Freeze for Config

§

impl Unpin for Config

§

impl UnsafeUnpin for Config

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.