Rust stdin
Nonblocking
OS | Status |
---|---|
Ubuntu-latest | |
macOS-latest | |
Windows-latest |
Dependency-less non-blocking stdin
reader using background threads. Supports streaming and immediate fallback defaults.
Install
Usage
Get stdin
or Default
use get_stdin_or_default;
let input = get_stdin_or_default;
assert_eq!;
Read stdin
as Stream
use spawn_stdin_stream;
use TryRecvError;
use Duration;
let stdin_stream = spawn_stdin_stream;
loop
Use with Tokio
Refer to the included Tokio Example App.
Related threads
- https://stackoverflow.com/questions/30012995/how-can-i-read-non-blocking-from-stdin
- https://www.reddit.com/r/rust/comments/fc71ju/how_to_read_from_stdin_without_blocking/?rdt=55515
License
MIT License (c) 2025 Jeremy Harris.