wasmer_wasi

Struct WasiStateBuilder

Source
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§

Source§

impl WasiStateBuilder

Source

pub fn env<Key, Value>(&mut self, key: Key, value: Value) -> &mut Self
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 arg<Arg>(&mut self, arg: Arg) -> &mut Self
where Arg: AsRef<[u8]>,

Add an argument.

Arguments must not contain the nul (0x0) byte

Source

pub fn envs<I, Key, Value>(&mut self, env_pairs: I) -> &mut Self
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 args<I, Arg>(&mut self, args: I) -> &mut Self
where I: IntoIterator<Item = Arg>, Arg: AsRef<[u8]>,

Add multiple arguments.

Arguments must not contain the nul (0x0) byte

Source

pub fn preopen_dir<FilePath>( &mut self, po_dir: FilePath, ) -> Result<&mut Self, WasiStateCreationError>
where FilePath: 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 preopen<F>( &mut self, inner: F, ) -> Result<&mut Self, WasiStateCreationError>
where F: Fn(&mut PreopenDirBuilder) -> &mut PreopenDirBuilder,

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()?;
Source

pub fn preopen_dirs<I, FilePath>( &mut self, po_dirs: I, ) -> Result<&mut Self, WasiStateCreationError>
where I: IntoIterator<Item = FilePath>, FilePath: 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 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<FilePath>( &mut self, alias: &str, po_dir: FilePath, ) -> Result<&mut Self, WasiStateCreationError>
where FilePath: AsRef<Path>,

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

Source

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

Preopen directorys with a different names exposed to the WASI.

Source

pub fn stdout( &mut self, new_file: Box<dyn VirtualFile + Send + Sync + 'static>, ) -> &mut 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 stderr( &mut self, new_file: Box<dyn VirtualFile + Send + Sync + 'static>, ) -> &mut 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 stdin( &mut self, new_file: Box<dyn VirtualFile + Send + Sync + 'static>, ) -> &mut 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_fs(&mut self, fs: Box<dyn FileSystem>) -> &mut Self

Sets the FileSystem to be used with this WASI instance.

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

Source

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

Configure the WASI filesystem before running.

Source

pub fn runtime<R>(&mut self, runtime: R) -> &mut Self
where R: WasiRuntimeImplementation + Send + Sync + 'static,

Sets the WASI runtime implementation and overrides the default implementation

Source

pub fn build(&mut self) -> Result<WasiState, WasiStateCreationError>

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.

Source

pub fn finalize( &mut self, store: &mut impl AsStoreMut, ) -> Result<WasiFunctionEnv, WasiStateCreationError>

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§

Source§

impl Debug for WasiStateBuilder

Source§

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

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

impl Default for WasiStateBuilder

Source§

fn default() -> WasiStateBuilder

Returns the “default value” for a type. 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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

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

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 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<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

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 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> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
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.
Source§

impl<T> Upcastable for T
where 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>) -> Box<dyn Any>

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