@@ -66,12 +66,12 @@ impl WasiCtxBuilder {
|
|||||||
Ok(self.0)
|
Ok(self.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn arg(&mut self, arg: &str) -> Result<&mut Self, StringArrayError> {
|
pub fn arg(mut self, arg: &str) -> Result<Self, StringArrayError> {
|
||||||
self.0.args.push(arg.to_owned())?;
|
self.0.args.push(arg.to_owned())?;
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stdin(&mut self, f: Box<dyn WasiFile>) -> &mut Self {
|
pub fn stdin(mut self, f: Box<dyn WasiFile>) -> Self {
|
||||||
self.0.insert_file(
|
self.0.insert_file(
|
||||||
0,
|
0,
|
||||||
f,
|
f,
|
||||||
@@ -80,7 +80,7 @@ impl WasiCtxBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stdout(&mut self, f: Box<dyn WasiFile>) -> &mut Self {
|
pub fn stdout(mut self, f: Box<dyn WasiFile>) -> Self {
|
||||||
self.0.insert_file(
|
self.0.insert_file(
|
||||||
1,
|
1,
|
||||||
f,
|
f,
|
||||||
@@ -89,7 +89,7 @@ impl WasiCtxBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stderr(&mut self, f: Box<dyn WasiFile>) -> &mut Self {
|
pub fn stderr(mut self, f: Box<dyn WasiFile>) -> Self {
|
||||||
self.0.insert_file(
|
self.0.insert_file(
|
||||||
2,
|
2,
|
||||||
f,
|
f,
|
||||||
@@ -98,17 +98,17 @@ impl WasiCtxBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inherit_stdio(&mut self) -> &mut Self {
|
pub fn inherit_stdio(self) -> Self {
|
||||||
self.stdin(Box::new(crate::stdio::stdin()))
|
self.stdin(Box::new(crate::stdio::stdin()))
|
||||||
.stdout(Box::new(crate::stdio::stdout()))
|
.stdout(Box::new(crate::stdio::stdout()))
|
||||||
.stderr(Box::new(crate::stdio::stderr()))
|
.stderr(Box::new(crate::stdio::stderr()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn preopened_dir(
|
pub fn preopened_dir(
|
||||||
&mut self,
|
mut self,
|
||||||
dir: Box<dyn WasiDir>,
|
dir: Box<dyn WasiDir>,
|
||||||
path: impl AsRef<Path>,
|
path: impl AsRef<Path>,
|
||||||
) -> Result<&mut Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let caps = DirCaps::all();
|
let caps = DirCaps::all();
|
||||||
let file_caps = FileCaps::all();
|
let file_caps = FileCaps::all();
|
||||||
self.0.table().push(Box::new(DirEntry::new(
|
self.0.table().push(Box::new(DirEntry::new(
|
||||||
@@ -120,7 +120,7 @@ impl WasiCtxBuilder {
|
|||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random(&mut self, random: Box<dyn RngCore>) -> &mut Self {
|
pub fn random(mut self, random: Box<dyn RngCore>) -> Self {
|
||||||
self.0.random.replace(random);
|
self.0.random.replace(random);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ mod string_array;
|
|||||||
pub mod table;
|
pub mod table;
|
||||||
pub mod virt;
|
pub mod virt;
|
||||||
|
|
||||||
pub use ctx::WasiCtx;
|
pub use cap_fs_ext::SystemTimeSpec;
|
||||||
pub use dir::{DirCaps, WasiDir};
|
pub use ctx::{WasiCtx, WasiCtxBuilder};
|
||||||
|
pub use dir::{DirCaps, ReaddirCursor, ReaddirEntity, WasiDir};
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
pub use file::{FileCaps, WasiFile};
|
pub use file::{FdFlags, FileCaps, Filestat, OFlags, WasiFile};
|
||||||
pub use string_array::StringArrayError;
|
pub use string_array::StringArrayError;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ impl Table {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Table {
|
Table {
|
||||||
map: HashMap::new(),
|
map: HashMap::new(),
|
||||||
next_key: 0,
|
next_key: 3, // 0, 1 and 2 are reserved for stdio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
pub use wasi_c2::WasiCtx;
|
pub use wasi_c2::{
|
||||||
|
Error, FdFlags, FileCaps, Filestat, OFlags, ReaddirCursor, ReaddirEntity, SystemTimeSpec,
|
||||||
|
WasiCtx, WasiCtxBuilder, WasiDir, WasiFile,
|
||||||
|
};
|
||||||
|
|
||||||
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing
|
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing
|
||||||
// with all the various WASI exports.
|
// with all the various WASI exports.
|
||||||
|
|||||||
Reference in New Issue
Block a user