Search code examples
ruststdin

Is there a Rust way to check if the STDIN buffer is empty before attempting to read it?


I want my application to be able to read the input from a redirected file stream through source > my_app, but I do not want it to ask for user input in case there is no redirection.

C provides such methods (Checking the stdin buffer if it's empty) but I could not find any solution for Rust.


Solution

  • As trentcl suggested, the way to do it is atty crate.