pub struct WasiStateBuilder { /* private fields */ }
Expand description

Convenient builder API for configuring WASI via WasiState.

Usage:

let mut state_builder = WasiState::new("wasi-prog-name");
state_builder
   .env("ENV_VAR", "ENV_VAL")
   .arg("--verbose")
   .preopen_dir("src")?
   .map_dir("name_wasi_sees", "path/on/host/fs")?
   .build();

Implementations§

Add an environment variable pair.

Both the key and value of an environment variable must not contain a nul byte (0x0), and the key must not contain the = byte (0x3d).

Add an argument.

Arguments must not contain the nul (0x0) byte

Add multiple environment variable pairs.

Both the key and value of the environment variables must not contain a nul byte (0x0), and the key must not contain the = byte (0x3d).

Add multiple arguments.

Arguments must not contain the nul (0x0) byte

Preopen a directory

This opens the given directory at the virtual root, /, and allows the WASI module to read and write to the given directory.

Preopen a directory and configure it.

Usage:

WasiState::new("program_name")
   .preopen(|p| p.directory("src").read(true).write(true).create(true))?
   .preopen(|p| p.directory(".").alias("dot").read(true))?
   .build()?;

Preopen a directory.

This opens the given directory at the virtual root, /, and allows the WASI module to read and write to the given directory.

Preopen the given directories from the Virtual FS.

Preopen a directory with a different name exposed to the WASI.

Preopen directorys with a different names exposed to the WASI.

Overwrite the default WASI stdout, if you want to hold on to the original stdout use WasiFs::swap_file after building.

Overwrite the default WASI stderr, if you want to hold on to the original stderr use WasiFs::swap_file after building.

Overwrite the default WASI stdin, if you want to hold on to the original stdin use WasiFs::swap_file after building.

Sets the FileSystem to be used with this WASI instance.

This is usually used in case a custom wasmer_vfs::FileSystem is needed.

Configure the WASI filesystem before running.

Sets the WASI runtime implementation and overrides the default implementation

Consumes the WasiStateBuilder and produces a WasiState

Returns the error from WasiFs::new if there’s an error

Calling build multiple times

Calling this method multiple times might not produce a determinisic result. This method is changing the builder’s internal state. The values set with the following methods are reset to their defaults:

Ideally, the builder must be refactord to update &mut self to mut self for every builder method, but it will break existing code. It will be addressed in a next major release.

Consumes the WasiStateBuilder and produces a WasiEnv

Returns the error from WasiFs::new if there’s an error.

Calling finalize multiple times

Calling this method multiple times might not produce a determinisic result. This method is calling Self::build, which is changing the builder’s internal state. See Self::build’s documentation to learn more.

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Deserializes using the given deserializer

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The type for metadata in pointers and references to Self.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more