WasiCtxBuilder: add methods to provide Files each for stdio (#147)

This commit is contained in:
Pat Hickey
2019-10-25 05:23:26 -07:00
committed by Jakub Konka
parent b0e896e7d0
commit f9a8329424

View File

@@ -96,6 +96,24 @@ impl WasiCtxBuilder {
Ok(self)
}
/// Provide a File to use as stdin
pub fn stdin(mut self, file: File) -> Result<Self> {
self.fds.insert(0, FdEntry::from(file)?);
Ok(self)
}
/// Provide a File to use as stdout
pub fn stdout(mut self, file: File) -> Result<Self> {
self.fds.insert(1, FdEntry::from(file)?);
Ok(self)
}
/// Provide a File to use as stderr
pub fn stderr(mut self, file: File) -> Result<Self> {
self.fds.insert(2, FdEntry::from(file)?);
Ok(self)
}
/// Add a preopened directory.
pub fn preopened_dir<P: AsRef<Path>>(mut self, dir: File, guest_path: P) -> Self {
self.preopens.push((guest_path.as_ref().to_owned(), dir));