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

Builder API for configuring a WasiEnv environment needed to run WASI modules.

Usage:

let mut state_builder = WasiEnv::builder("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_init()?;

Implementations§

source§

impl WasiEnvBuilder

source

pub fn new(program_name: impl Into<String>) -> Self

Creates an empty WasiEnvBuilder.

source

pub fn env<Key, Value>(self, key: Key, value: Value) -> Selfwhere Key: AsRef<[u8]>, Value: AsRef<[u8]>,

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).

source

pub fn add_env<Key, Value>(&mut self, key: Key, value: Value)where Key: AsRef<[u8]>, Value: AsRef<[u8]>,

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).

source

pub fn envs<I, Key, Value>(self, env_pairs: I) -> Selfwhere I: IntoIterator<Item = (Key, Value)>, Key: AsRef<[u8]>, Value: AsRef<[u8]>,

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).

source

pub fn add_envs<I, Key, Value>(&mut self, env_pairs: I)where I: IntoIterator<Item = (Key, Value)>, Key: AsRef<[u8]>, Value: AsRef<[u8]>,

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).

source

pub fn get_env(&self) -> &[(String, Vec<u8>)]

Get a reference to the configured environment variables.

source

pub fn get_env_mut(&mut self) -> &mut Vec<(String, Vec<u8>)>

Get a mutable reference to the configured environment variables.

source

pub fn arg<V>(self, arg: V) -> Selfwhere V: AsRef<[u8]>,

Add an argument.

Arguments must not contain the nul (0x0) byte

source

pub fn add_arg<V>(&mut self, arg: V)where V: AsRef<[u8]>,

Add an argument.

Arguments must not contain the nul (0x0) byte.

source

pub fn args<I, Arg>(self, args: I) -> Selfwhere I: IntoIterator<Item = Arg>, Arg: AsRef<[u8]>,

Add multiple arguments.

Arguments must not contain the nul (0x0) byte

source

pub fn add_args<I, Arg>(&mut self, args: I)where I: IntoIterator<Item = Arg>, Arg: AsRef<[u8]>,

Add multiple arguments.

Arguments must not contain the nul (0x0) byte

source

pub fn get_args(&self) -> &[String]

Get a reference to the configured arguments.

source

pub fn get_args_mut(&mut self) -> &mut Vec<String>

Get a mutable reference to the configured arguments.

source

pub fn use_webc<Name>(self, webc: Name) -> Selfwhere Name: AsRef<str>,

Adds a container this module inherits from

source

pub fn uses<I>(self, uses: I) -> Selfwhere I: IntoIterator<Item = String>,

Adds a list of other containers this module inherits from

source

pub fn include_webc<Name>(self, webc: Name) -> Selfwhere Name: AsRef<str>,

Includes a webc package to use instead of downloading them from the registry

source

pub fn include_webcs<I>(self, webcs: I) -> Selfwhere I: IntoIterator<Item = String>,

Adds a list of webc packages to use instead of downloading them from the registry

source

pub fn map_command<Name, Target>(self, name: Name, target: Target) -> Selfwhere Name: AsRef<str>, Target: AsRef<str>,

Map an atom to a local binary

source

pub fn map_commands<I, Name, Target>(self, map_commands: I) -> Selfwhere I: IntoIterator<Item = (Name, Target)>, Name: AsRef<str>, Target: AsRef<str>,

Maps a series of atoms to the local binaries

source

pub fn preopen_dir<P>(self, po_dir: P) -> Result<Self, WasiStateCreationError>where P: AsRef<Path>,

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.

source

pub fn add_preopen_dir<P>( &mut self, po_dir: P ) -> Result<(), WasiStateCreationError>where P: AsRef<Path>,

Adds a 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.

source

pub fn preopen_dirs<I, P>(self, dirs: I) -> Result<Self, WasiStateCreationError>where I: IntoIterator<Item = P>, P: AsRef<Path>,

Preopen multiple directories.

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

source

pub fn preopen_build<F>(self, inner: F) -> Result<Self, WasiStateCreationError>where F: Fn(&mut PreopenDirBuilder) -> &mut PreopenDirBuilder,

Preopen a directory and configure it.

Usage:

WasiEnv::builder("program_name")
   .preopen_build(|p| p.directory("src").read(true).write(true).create(true))?
   .preopen_build(|p| p.directory(".").alias("dot").read(true))?
   .build_init()?;
source

pub fn add_preopen_build<F>( &mut self, inner: F ) -> Result<(), WasiStateCreationError>where F: Fn(&mut PreopenDirBuilder) -> &mut PreopenDirBuilder,

Preopen a directory and configure it.

Usage:

WasiEnv::builder("program_name")
   .preopen_build(|p| p.directory("src").read(true).write(true).create(true))?
   .preopen_build(|p| p.directory(".").alias("dot").read(true))?
   .build_init()?;
source

pub fn preopen_vfs_dirs<I>( &mut self, po_dirs: I ) -> Result<&mut Self, WasiStateCreationError>where I: IntoIterator<Item = String>,

Preopen the given directories from the Virtual FS.

source

pub fn map_dir<P>( self, alias: &str, po_dir: P ) -> Result<Self, WasiStateCreationError>where P: AsRef<Path>,

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

source

pub fn add_map_dir<P>( &mut self, alias: &str, po_dir: P ) -> Result<(), WasiStateCreationError>where P: AsRef<Path>,

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

source

pub fn map_dirs<I, P>( self, mapped_dirs: I ) -> Result<Self, WasiStateCreationError>where I: IntoIterator<Item = (String, P)>, P: AsRef<Path>,

Preopen directorys with a different names exposed to the WASI.

source

pub fn stdout( self, new_file: Box<dyn VirtualFile + Send + Sync + 'static> ) -> Self

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

source

pub fn set_stdout( &mut self, new_file: Box<dyn VirtualFile + Send + Sync + 'static> )

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

source

pub fn stderr( self, new_file: Box<dyn VirtualFile + Send + Sync + 'static> ) -> Self

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

source

pub fn set_stderr( &mut self, new_file: Box<dyn VirtualFile + Send + Sync + 'static> )

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

source

pub fn stdin( self, new_file: Box<dyn VirtualFile + Send + Sync + 'static> ) -> Self

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

source

pub fn set_stdin( &mut self, new_file: Box<dyn VirtualFile + Send + Sync + 'static> )

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

source

pub fn fs(self, fs: Box<dyn FileSystem + Send + Sync>) -> Self

Sets the FileSystem to be used with this WASI instance.

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

source

pub fn set_fs(&mut self, fs: Box<dyn FileSystem + Send + Sync>)

source

pub fn sandbox_fs(self, fs: TmpFileSystem) -> Self

Sets a new sandbox FileSystem to be used with this WASI instance.

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

source

pub fn setup_fs( self, setup_fs_fn: Box<dyn Fn(&WasiInodes, &mut WasiFs) -> Result<(), String> + Send> ) -> Self

Configure the WASI filesystem before running.

source

pub fn runtime(self, runtime: Arc<dyn WasiRuntime + Send + Sync>) -> Self

Sets the WASI runtime implementation and overrides the default implementation

source

pub fn set_runtime(&mut self, runtime: Arc<dyn WasiRuntime + Send + Sync>)

source

pub fn compiled_modules(self, compiled_modules: Arc<ModuleCache>) -> Self

Sets the compiled modules to use with this builder (sharing the cached modules is better for performance and memory consumption)

source

pub fn capabilities(self, capabilities: Capabilities) -> Self

source

pub fn capabilities_mut(&mut self) -> &mut Capabilities

source

pub fn set_capabilities(&mut self, capabilities: Capabilities)

source

pub fn build_init(self) -> Result<WasiEnvInit, WasiStateCreationError>

Consumes the WasiEnvBuilder and produces a WasiEnvInit, which can be used to construct a new WasiEnv with [WasiEnv::new].

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

NOTE: You should prefer to not work directly with WasiEnvInit. Use WasiEnvBuilder::run or WasiEnvBuilder::run_with_store instead to ensure proper invokation of WASI modules.

source

pub fn build(self) -> Result<WasiEnv, WasiRuntimeError>

source

pub fn instantiate( self, module: Module, store: &mut impl AsStoreMut ) -> Result<(Instance, WasiFunctionEnv), WasiRuntimeError>

Consumes the WasiEnvBuilder and produces a WasiEnvInit, which can be used to construct a new WasiEnv with [WasiEnv::new].

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

source

pub fn run(self, module: Module) -> Result<(), WasiRuntimeError>

source

pub fn run_with_store( self, module: Module, store: &mut impl AsStoreMut ) -> Result<(), WasiRuntimeError>

Trait Implementations§

source§

impl Debug for WasiEnvBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for WasiEnvBuilder

source§

fn default() -> WasiEnvBuilder

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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
§

impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
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<T> Upcastable for Twhere T: Any + Debug + 'static,

source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

source§

fn upcast_any_box(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

§

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more