Struct wasmer_wasi::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
sourceimpl WasiStateBuilder
impl WasiStateBuilder
sourcepub fn env<Key, Value>(&mut self, key: Key, value: Value) -> &mut Self where
Key: AsRef<[u8]>,
Value: AsRef<[u8]>,
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
).
sourcepub fn arg<Arg>(&mut self, arg: Arg) -> &mut Self where
Arg: AsRef<[u8]>,
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
sourcepub fn envs<I, Key, Value>(&mut self, env_pairs: I) -> &mut Self where
I: IntoIterator<Item = (Key, Value)>,
Key: AsRef<[u8]>,
Value: AsRef<[u8]>,
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
).
sourcepub fn args<I, Arg>(&mut self, args: I) -> &mut Self where
I: IntoIterator<Item = Arg>,
Arg: AsRef<[u8]>,
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
sourcepub fn preopen_dir<FilePath>(
&mut self,
po_dir: FilePath
) -> Result<&mut Self, WasiStateCreationError> where
FilePath: AsRef<Path>,
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.
sourcepub fn preopen<F>(
&mut self,
inner: F
) -> Result<&mut Self, WasiStateCreationError> where
F: Fn(&mut PreopenDirBuilder) -> &mut PreopenDirBuilder,
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()?;
sourcepub fn preopen_dirs<I, FilePath>(
&mut self,
po_dirs: I
) -> Result<&mut Self, WasiStateCreationError> where
I: IntoIterator<Item = FilePath>,
FilePath: AsRef<Path>,
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.
sourcepub fn preopen_vfs_dirs<I>(
&mut self,
po_dirs: I
) -> Result<&mut Self, WasiStateCreationError> where
I: IntoIterator<Item = String>,
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.
sourcepub fn map_dir<FilePath>(
&mut self,
alias: &str,
po_dir: FilePath
) -> Result<&mut Self, WasiStateCreationError> where
FilePath: AsRef<Path>,
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.
sourcepub fn map_dirs<I, FilePath>(
&mut self,
mapped_dirs: I
) -> Result<&mut Self, WasiStateCreationError> where
I: IntoIterator<Item = (String, FilePath)>,
FilePath: AsRef<Path>,
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.
sourcepub fn stdout(&mut self, new_file: Box<dyn VirtualFile>) -> &mut Self
pub fn stdout(&mut self, new_file: Box<dyn VirtualFile>) -> &mut Self
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 Self
pub fn stderr(&mut self, new_file: Box<dyn VirtualFile>) -> &mut Self
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 Self
pub fn stdin(&mut self, new_file: Box<dyn VirtualFile>) -> &mut Self
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 Self
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.
sourcepub fn setup_fs(
&mut self,
setup_fs_fn: Box<dyn Fn(&mut WasiFs) -> Result<(), String> + Send>
) -> &mut Self
pub fn setup_fs(
&mut self,
setup_fs_fn: Box<dyn Fn(&mut WasiFs) -> Result<(), String> + Send>
) -> &mut Self
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
sourceimpl Debug for WasiStateBuilder
impl Debug for WasiStateBuilder
sourceimpl Default for WasiStateBuilder
impl Default for WasiStateBuilder
sourcefn default() -> WasiStateBuilder
fn default() -> WasiStateBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl !RefUnwindSafe for WasiStateBuilder
impl Send for WasiStateBuilder
impl !Sync for WasiStateBuilder
impl Unpin for WasiStateBuilder
impl !UnwindSafe for WasiStateBuilder
Blanket Implementations
impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
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 F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> Upcastable for T where
T: 'static + Any + Debug,
impl<T> Upcastable for T where
T: 'static + Any + Debug,
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_box(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more