by apitman · 2y ago · 0 comments
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
And I just looked it up and it's right there in the docs, too: https://doc.rust-lang.org/std/io/struct.Stdin.htmlYou basically shouldn't use `tokio::io::stdin()` for what you want, as is documented at https://docs.rs/tokio/latest/tokio/io/fn.stdin.html
> For interactive uses, it is recommended to spawn a thread dedicated to user input and use blocking IO directly in that thread.
So the code under tokio would be
let line = rt.spawn_blocking(|| {
use std::io::stdin;
let mut buffer = String::new();
stdin().read_line(&mut buffer).unwrap()
}).await.unwrap();