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
impl WasiStateBuilder
Sourcepub fn env<Key, Value>(
&mut self,
key: Key,
value: Value,
) -> &mut WasiStateBuilder
pub fn env<Key, Value>( &mut self, key: Key, value: Value, ) -> &mut WasiStateBuilder
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
).
Sourcepub fn arg<Arg>(&mut self, arg: Arg) -> &mut WasiStateBuilder
pub fn arg<Arg>(&mut self, arg: Arg) -> &mut WasiStateBuilder
Add an argument.
Arguments must not contain the nul (0x0) byte
Sourcepub fn envs<I, Key, Value>(&mut self, env_pairs: I) -> &mut WasiStateBuilder
pub fn envs<I, Key, Value>(&mut self, env_pairs: I) -> &mut WasiStateBuilder
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
).
Sourcepub fn args<I, Arg>(&mut self, args: I) -> &mut WasiStateBuilder
pub fn args<I, Arg>(&mut self, args: I) -> &mut WasiStateBuilder
Add multiple arguments.
Arguments must not contain the nul (0x0) byte
Sourcepub fn preopen_dir<FilePath>(
&mut self,
po_dir: FilePath,
) -> Result<&mut WasiStateBuilder, WasiStateCreationError>
pub fn preopen_dir<FilePath>( &mut self, po_dir: FilePath, ) -> Result<&mut WasiStateBuilder, WasiStateCreationError>
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.
Sourcepub fn preopen<F>(
&mut self,
inner: F,
) -> Result<&mut WasiStateBuilder, WasiStateCreationError>where
F: Fn(&mut PreopenDirBuilder) -> &mut PreopenDirBuilder,
pub fn preopen<F>(
&mut self,
inner: F,
) -> Result<&mut WasiStateBuilder, 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()?;
Sourcepub fn preopen_dirs<I, FilePath>(
&mut self,
po_dirs: I,
) -> Result<&mut WasiStateBuilder, WasiStateCreationError>
pub fn preopen_dirs<I, FilePath>( &mut self, po_dirs: I, ) -> Result<&mut WasiStateBuilder, WasiStateCreationError>
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.
Sourcepub fn preopen_vfs_dirs<I>(
&mut self,
po_dirs: I,
) -> Result<&mut WasiStateBuilder, WasiStateCreationError>where
I: IntoIterator<Item = String>,
pub fn preopen_vfs_dirs<I>(
&mut self,
po_dirs: I,
) -> Result<&mut WasiStateBuilder, WasiStateCreationError>where
I: IntoIterator<Item = String>,
Preopen the given directories from the Virtual FS.
Sourcepub fn map_dir<FilePath>(
&mut self,
alias: &str,
po_dir: FilePath,
) -> Result<&mut WasiStateBuilder, WasiStateCreationError>
pub fn map_dir<FilePath>( &mut self, alias: &str, po_dir: FilePath, ) -> Result<&mut WasiStateBuilder, WasiStateCreationError>
Preopen a directory with a different name exposed to the WASI.
Sourcepub fn map_dirs<I, FilePath>(
&mut self,
mapped_dirs: I,
) -> Result<&mut WasiStateBuilder, WasiStateCreationError>
pub fn map_dirs<I, FilePath>( &mut self, mapped_dirs: I, ) -> Result<&mut WasiStateBuilder, WasiStateCreationError>
Preopen directorys with a different names exposed to the WASI.
Sourcepub fn stdout(
&mut self,
new_file: Box<dyn VirtualFile>,
) -> &mut WasiStateBuilder
pub fn stdout( &mut self, new_file: Box<dyn VirtualFile>, ) -> &mut WasiStateBuilder
Overwrite the default WASI stdout
, if you want to hold on to the
original stdout
use WasiFs::swap_file
after building.
Sourcepub fn stderr(
&mut self,
new_file: Box<dyn VirtualFile>,
) -> &mut WasiStateBuilder
pub fn stderr( &mut self, new_file: Box<dyn VirtualFile>, ) -> &mut WasiStateBuilder
Overwrite the default WASI stderr
, if you want to hold on to the
original stderr
use WasiFs::swap_file
after building.
Sourcepub fn stdin(&mut self, new_file: Box<dyn VirtualFile>) -> &mut WasiStateBuilder
pub fn stdin(&mut self, new_file: Box<dyn VirtualFile>) -> &mut WasiStateBuilder
Overwrite the default WASI stdin
, if you want to hold on to the
original stdin
use WasiFs::swap_file
after building.
Sourcepub fn set_fs(&mut self, fs: Box<dyn FileSystem>) -> &mut WasiStateBuilder
pub fn set_fs(&mut self, fs: Box<dyn FileSystem>) -> &mut WasiStateBuilder
Sets the FileSystem to be used with this WASI instance.
This is usually used in case a custom wasmer_vfs::FileSystem
is needed.
Sourcepub fn setup_fs(
&mut self,
setup_fs_fn: Box<dyn Fn(&mut WasiFs) -> Result<(), String> + Send>,
) -> &mut WasiStateBuilder
pub fn setup_fs( &mut self, setup_fs_fn: Box<dyn Fn(&mut WasiFs) -> Result<(), String> + Send>, ) -> &mut WasiStateBuilder
Configure the WASI filesystem before running.
Sourcepub fn build(&mut self) -> Result<WasiState, WasiStateCreationError>
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.
Sourcepub fn finalize(&mut self) -> Result<WasiEnv, WasiStateCreationError>
pub fn finalize(&mut self) -> Result<WasiEnv, 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
impl Debug for WasiStateBuilder
Source§impl Default for WasiStateBuilder
impl Default for WasiStateBuilder
Source§fn default() -> WasiStateBuilder
fn default() -> WasiStateBuilder
Auto Trait Implementations§
impl Freeze for WasiStateBuilder
impl !RefUnwindSafe for WasiStateBuilder
impl Send for WasiStateBuilder
impl !Sync for WasiStateBuilder
impl Unpin for WasiStateBuilder
impl !UnwindSafe for WasiStateBuilder
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more