Crates.io | tokio-stdin |
lib.rs | tokio-stdin |
version | 0.1.2 |
source | src |
created_at | 2017-10-01 15:21:22.4177 |
updated_at | 2019-07-09 23:39:11.55791 |
description | Read from stdin as a Tokio stream |
homepage | |
repository | https://github.com/paulkernfeld/tokio-stdin |
max_upload_size | |
id | 34094 |
size | 6,791 |
NOTE: This library is no longer necessary. As of tokio
0.1.6, it is now possible to read
from stdin without the overhead of spawning a separate thread with the tokio::io::stdin
function.
Read from stdin as a Tokio stream by spawning a separate thread.
extern crate futures;
extern crate tokio_stdin;
fn main() {
use futures::Stream;
tokio_stdin::spawn_stdin_stream_unbounded().wait();
}
As far as I know, this is currently the recommended way to do this. On Dec 29, 2016, alexcrichton commented:
In general for small CLI tools and such what you probably want to do is to use channels to communicate to foreign threads. You can have a thread per stdin/stdout/stderr with a
futures::sync::mpsc
that the main thread communicates with.
This crate locks stdin while it's running, so trying to read from stdin in another part of your code will probably cause a deadlock.
See the count_keys
example for a simple use of this.
License: MIT/Apache-2.0