I'm having trouble with stdin in Rust. I'm trying to process stdin comming from a pipe on a linux terminal, something like grep for example.
echo "lorem ipsum" | grep <text>
Im using this in rust:
fn load_stdin() -> Result<String> {
let mut buffer = String::new();
let stdin = stdin();
stdin.read_line(&mut buffer)?;
return Ok(buffer);
}
But the problem is that if I don't bring in any piped data I get prompted to write, I would instead like to return Err.
So basically, if I do something like:
ls | cargo run
user@machine: ~ $
All is good. But if I do not pipe any stdin:
cargo run
The program halts and waits for user input.