Using the termion crate, while it works perfectly, how come it infinitely takes input from my keyboard?
use termion::input::TermRead;
use termion::event::Key;
use std::process;
fn main()
{
// Keys
let keys = std::io::stdin().keys();
for key in keys
{
let key = key.expect("failed to read key");
if key == Key::Char('q')
{
process::exit(0);
}
}
}
So here is the for loop, so does this for loop loops through infinite amount of times?
And, finally, reading from Stdin ends when the corresponding handle is closed. If there's no redirection, i.e. standard input is connected to the terminal, that means - until the terminal itself is closed.
If I understood you correctly, after executing let keys = std::io::stdin().keys();, Then in the next line which is for key in keys, it loops through infinitly because the list of keys is infinite?