Skip to main content

WasiConfig

Struct WasiConfig 

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

WASI (WebAssembly System Interface) configuration for zwasm modules.

Supports WASI Preview 1 and 2, full syscalls, stdio overrides, preopened directories, and environment/argv configuration. Used to provide system interface capabilities to Wasm modules running in the zwasm runtime.

Implementations§

Source§

impl WasiConfig

Source

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

Creates a new WASI configuration for zwasm modules.

Supports both WASI Preview 1 and 2. Use this to provide system interface capabilities to Wasm code.

Source

pub fn set_argv(&mut self, argv: &[&str]) -> Result<(), ZwasmError>

Sets the argv (command-line arguments) for the guest process.

These will be visible to the Wasm module via WASI syscalls.

Source

pub fn set_env(&mut self, env: &[(&str, &str)]) -> Result<(), ZwasmError>

Sets environment variables for the guest process.

These will be visible to the Wasm module via WASI syscalls.

Source

pub fn preopen_dir( &mut self, host_path: &str, guest_path: &str, ) -> Result<(), ZwasmError>

Preopens a host directory at a guest-visible path for the Wasm module.

Grants the guest access to the specified host directory under the given guest path.

§Safety

This method grants the guest access to host filesystem resources. Callers must ensure the mapped host path is intended to be exposed to untrusted Wasm code.

Source

pub fn preopen_fd( &mut self, host_fd: isize, guest_path: &str, kind: u8, ownership: u8, ) -> Result<(), ZwasmError>

Preopens an existing host file descriptor at a guest-visible path for the Wasm module.

Useful for passing already-opened files or sockets into the guest.

§Safety

This method transfers or borrows host FD capabilities into the guest, depending on ownership. Callers must ensure FD lifetime/ownership policy matches the supplied flag and that exposing the FD to guest code is acceptable.

Source

pub fn set_stdio_fd( &mut self, wasi_fd: u32, host_fd: isize, ownership: u8, ) -> Result<(), ZwasmError>

Overrides WASI stdio file descriptor mapping (stdin, stdout, stderr).

Allows redirecting guest stdio to custom host file descriptors.

§Safety

The runtime may close or retain the supplied host_fd based on ownership. Callers must ensure ownership mode is correct to avoid double-close or leaked descriptors.

Trait Implementations§

Source§

impl Drop for WasiConfig

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§

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.