tokio-stdin

Crates.iotokio-stdin
lib.rstokio-stdin
version0.1.2
sourcesrc
created_at2017-10-01 15:21:22.4177
updated_at2019-07-09 23:39:11.55791
descriptionRead from stdin as a Tokio stream
homepage
repositoryhttps://github.com/paulkernfeld/tokio-stdin
max_upload_size
id34094
size6,791
Paul Kernfeld (paulkernfeld)

documentation

https://docs.rs/tokio-stdin

README

tokio-stdin

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

Commit count: 8

cargo fmt