How to Use piped stdin/stdout in Rust CLI Tools

Cli
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(())
}