async_wasi/snapshots/
mod.rs

1pub mod common;
2pub mod env;
3pub mod preview_1;
4
5use common::error::Errno;
6
7use self::env::{vfs::WasiFileSys, VFS};
8
9#[derive(Debug)]
10pub struct WasiCtx {
11    pub args: Vec<String>,
12    envs: Vec<String>,
13    pub(crate) vfs: VFS,
14    pub exit_code: u32,
15}
16impl Default for WasiCtx {
17    fn default() -> Self {
18        Self::new()
19    }
20}
21impl WasiCtx {
22    pub fn new() -> Self {
23        WasiCtx {
24            args: vec![],
25            envs: vec![],
26            vfs: VFS::new(),
27            exit_code: 0,
28        }
29    }
30
31    pub fn create_with_vfs(vfs: VFS) -> Self {
32        Self {
33            args: vec![],
34            envs: vec![],
35            vfs,
36            exit_code: 0,
37        }
38    }
39
40    pub fn mount_file_sys(
41        &mut self,
42        guest_path: &str,
43        file_sys: Box<dyn WasiFileSys<Index = usize> + Send + Sync>,
44    ) {
45        self.vfs.mount_file_sys(guest_path, file_sys)
46    }
47
48    pub fn push_arg(&mut self, arg: String) {
49        self.args.push(arg);
50    }
51
52    pub fn push_args(&mut self, args: Vec<String>) {
53        self.args.extend(args);
54    }
55
56    /// The format of the `env` argument should be "KEY=VALUE"
57    pub fn push_env(&mut self, env: String) {
58        self.envs.push(env);
59    }
60
61    pub fn push_envs(&mut self, envs: Vec<String>) {
62        self.envs.extend(envs);
63    }
64}
65
66// unsafe impl Send for WasiCtx {}
67// unsafe impl Sync for WasiCtx {}