[−][src]Crate wasi_process
A library to run wasi modules as pseudo-processes.
use wasmer_wasi::{WasiEnv, WasiState, WasiVersion}; use wasi_process::WasiProcess; let store = wasmer::Store::default(); let wasm = include_bytes!("../helloworld.wasm"); // just write(1, "Hello, World!\n", 14) let module = wasmer::Module::new(&store, wasm)?; let mut state = WasiState::new("progg"); wasi_process::add_stdio(&mut state); state.args(&["foo", "bar"]); let imports = wasmer_wasi::generate_import_object_from_env( &store, WasiEnv::new(state.build()?), wasmer_wasi::get_wasi_version(&module, false).unwrap_or(WasiVersion::Latest), ); let instance = wasmer::Instance::new(&module, &imports)?; let mut wasi = WasiProcess::new(&instance, wasi_process::MaxBufSize::default())?; let mut stdout = wasi.stdout.take().unwrap(); wasi.spawn(); let mut out = String::new(); stdout.read_to_string(&mut out).await?; assert_eq!(out, "Hello, World!\n");
Structs
MaxBufSize | A struct to configure the sizes of the internal buffers used for stdio. |
SpawnHandle | A handle to a spawned a wasi process. |
Stderr | The stderr pseudo-file for wasi processes. |
Stdin | The stdin pseudo-file for wasi processes. |
Stdout | The stdout pseudo-file for wasi processes. |
WasiProcess | A wasi process. See crate documentation for more details and examples. |
WasiStderr | An AsyncRead type representing a wasi stderr stream. |
WasiStdin | An AsyncWrite type representing a wasi stdin stream. |
WasiStdout | An AsyncRead type representing a wasi stdout stream. |
Enums
SpawnError | An error returned from a spawned process. Either an error from tokio's |
Functions
add_stdio | Use the wasi-process stdio pseudo-files for a wasi environment. |