I/O-free process client library written in Rust
This library provides an I/O-agnostic abstraction over process operations — spawning commands, waiting for exit status, and collecting output — based on three concepts:
A coroutine is an I/O-free, resumable and composable state machine. It emits I/O requests without performing any I/O itself, and receives I/O responses to make progress. A coroutine is terminated when it stops emitting I/O requests.
See available coroutines at ./src/coroutines.
A runtime contains all the I/O logic. It is responsible for processing I/O requests and returning the corresponding I/O responses. A runtime targets a specific execution model (blocking std, async Tokio).
See available runtimes at ./src/runtimes.
The loop is the glue between coroutines and runtimes. It drives the coroutine forward by feeding each ProcessOutput back as the next argument, until the coroutine terminates.
use io_process::{
command::Command,
coroutines::spawn::{Spawn, SpawnResult},
runtimes::std::handle,
};
let mut command = Command::new("ls");
command.arg("-al");
command.arg("/tmp");
let mut arg = None;
let mut spawn = Spawn::new(command);
let status = loop {
match spawn.resume(arg.take()) {
SpawnResult::Ok { status } => break status,
SpawnResult::Io { input } => arg = Some(handle(input).unwrap()),
SpawnResult::Err { err } => panic!("{err}"),
}
};use io_process::{
command::Command,
coroutines::spawn_out::{SpawnOut, SpawnOutResult},
runtimes::tokio::handle,
};
let mut command = Command::new("echo");
command.arg("hello");
command.arg("world");
let mut arg = None;
let mut spawn = SpawnOut::new(command);
let (status, stdout, stderr) = loop {
match spawn.resume(arg.take()) {
SpawnOutResult::Ok { status, stdout, stderr } => break (status, stdout, stderr),
SpawnOutResult::Io { input } => arg = Some(handle(input).await.unwrap()),
SpawnOutResult::Err { err } => panic!("{err}"),
}
};See complete examples at ./examples.
Have a look at projects built on top of this library:
This project is licensed under either of:
at your option.
- Chat on Matrix
- News on Mastodon or RSS
- Mail at pimalaya.org@posteo.net
Special thanks to the NLnet foundation and the European Commission that have been financially supporting the project for years:
- 2022: NGI Assure
- 2023: NGI Zero Entrust
- 2024: NGI Zero Core (still ongoing in 2026)
If you appreciate the project, feel free to donate using one of the following providers:
