Giter VIP home page Giter VIP logo

tokio-stdin-stdout's Introduction

tokio-stdin-stdout

AsyncRead/AsyncWrite stdin/stdout for Tokio

Documentation - more description there

Example

let mut core = tokio_core::reactor::Core::new()?;

let stdin = tokio_stdin_stdout::stdin(0);
let stdout = tokio_stdin_stdout::stdout(0);

core.run(tokio_io::io::copy(stdin, stdout))?;

Additional examples

  1. loop.rs - Write hello ten times
  2. line-by-line.rs - Convert all input text to ASCII upper case, line by line. This example also demonstrates usage of tokio-codec and various modes of starting Tokio programs (multithreaded, singlethreaded).

async fn demo

Not much related to tokio-stdin-stdout, but there are some async fn examples runnable by cargo script.

They require nightly Rust.

Alternatives

  1. tokio-stdin no AsyncRead, only stdin, byte by byte
  2. tokio-file-unix - better, but only Unix

tokio-stdin-stdout's People

Contributors

cmichi avatar vi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

cmichi

tokio-stdin-stdout's Issues

Writing to channel from loop

Hi there,

I'm quite new to Rust and struggle with this:

extern crate tokio_io;
extern crate tokio_stdin_stdout;

use tokio_io::io::write_all as tokio_write_all;

fn main() {
  let stdout = tokio_stdin_stdout::stdout(0);

  for _ in 1..10 {
    tokio_write_all(stdout, "hello");
  }
}

My real code looks different, but I could reduce it down to this simplified example. Basically I want to write stuff to the stdout sink from a loop, but the compiler always complains:

11 |             tokio_write_all(stdout, "hello");
   |                             ^^^^^^ value moved here in previous iteration of loop

This makes sense and I thought I would go for tokio_write_all(stdout.clone(), "hello"); or tokio_write_all(&stdout, "hello"); instead, but both don't work.

So I'm wondering: Am I just not on the right track or is this currently not possible with the library (because e.g. the clone() trait is not implemented)?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.