Alternative IO: altio 0.1.0 published

Why this crate

Interactive command tools utilize stdin, stdout and stderr for communication. If you want to use command tools as libraries(no spawning processes) and tool authors agree, this crate can help to automating input/output, just 3 steps:

  1. Use proc macro attribute to #[define] a module, e.g. #[::altio::define] pub mod io {}.

  2. Replace std APIs with altio's equivalents, e.g. replace println!() with io_println!(), replace std::io::stdin() with io::altin().

  3. Keep as simple as possible, e.g. fn main() { the_tool::run( std::env::args_os() )}.

Example for tool authors

[dependencies] altio = "0.1" once_cell = { version = "1.19.0", optional = true } [features] altio = ["once_cell"]
// #[::altio::define] pub mod io {}

When building the tool as an application, the "altio" feature is disabled and altio falls back to stdio.

When building the tool as a library, the tool users can invoke send/recv methods to communicate with the tool, e.g. send_line(), try_recv_line().

Example for tool users

the_tool = { version = "0.1", features = ["altio"] }
let args = std::env::args_os(); // clap::Parser::parse_from()
std::thread::spawn( || the_tool::run( args ) ); // `io::altin().read_line()` called occasionally

loop {
    if let Some( received ) = the_tool::io::try_recv_line() {
        if received == "lorum" {
            io::send_line( "ipsum".to_owned() );


Under Apache License 2.0 or MIT License, at your will.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.