Skip to content

Commit 26bc178

Browse files
committed
wasi-common: add preopened_handle, to be able to open any handle
1 parent 7ed7c08 commit 26bc178

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/wasi-common/src/ctx.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,22 @@ impl WasiCtxBuilder {
268268
self
269269
}
270270

271+
/// Add a preopened handle.
272+
///
273+
/// This is the most generic function for adding a directory, but also the less easy to use.
274+
pub fn preopened_handle<P: AsRef<Path>, T: 'static + Handle>(
275+
&mut self,
276+
dir: T,
277+
guest_path: P,
278+
) -> &mut Self {
279+
let preopen = PendingPreopen::new(move || Ok(Box::new(dir)));
280+
self.preopens
281+
.as_mut()
282+
.unwrap()
283+
.push((guest_path.as_ref().to_owned(), preopen));
284+
self
285+
}
286+
271287
/// Build a `WasiCtx`, consuming this `WasiCtxBuilder`.
272288
///
273289
/// If any of the arguments or environment variables in this builder cannot be converted into

0 commit comments

Comments
 (0)