expression
Pipe-friendly standard input and output
A CLI filter reads from standard input and writes records to standard output, so another process can consume them. EOF ends the loop. This fixture supplies small trusted UTF-8 lines; production processing of untrusted data needs an explicit record-size limit. Fixture: stdin 'rust book\npython\nrust code\n'. Expected stdout (not executed): rust book rust code Expected stderr: (empty) Expected exit: 0 Common mistake: Writing a human banner to stdout before machine-consumable records.
Formal Syntax & Structure
rust syntaxrust
for line in stdin.lock().lines() { ... }Working Example
Example Snippetrust
fn main() -> std::io::Result<()> { use std::io::{self, BufRead, Write}; let input = io::stdin(); let mut output = io::stdout().lock(); for line in input.lock().lines() { let line = line?; if line.contains("rust") { writeln!(output, "{line}")?; } } output.flush()?; Ok(())}