[−][src]Crate wasi_process
A library to run wasi modules as pseudo-processes.
use wasmer_wasi::{WasiVersion, state::WasiState}; use wasi_process::WasiProcess; let wasm = include_bytes!("../helloworld.wasm"); // just write(1, "Hello, World!\n", 14) let module = wasmer_runtime::compile(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_state( state.build()?, wasmer_wasi::get_wasi_version(&module, false).unwrap_or(WasiVersion::Latest), ); let mut wasi = WasiProcess::new(module.instantiate(&imports)?); 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
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. |