Use std::io::stdin() and stdout() for internal piping or Stdio::piped() with Command for external tool integration.
Use std::io::stdin() to read input and std::io::stdout().write() to write output, or chain commands via Command with Stdio::piped() for external tools.
use std::io::{self, Write};
fn main() -> io::Result<()> {
let mut input = String::new();
io::stdin().read_line(&mut input)?;
io::stdout().write_all(input.as_bytes())?;
Ok(())
}
Piping stdin and stdout lets your Rust program accept text from the keyboard or another program and send text back to the screen or another program. It works like a digital hose connecting the output of one tool to the input of another. You use it to build command-line tools that can be chained together in a shell.