Skip to content

Instantly share code, notes, and snippets.

@vi
Created October 9, 2017 19:15
Show Gist options
  • Save vi/f4be6e945bb5a836edb15de0257b8af5 to your computer and use it in GitHub Desktop.
Save vi/f4be6e945bb5a836edb15de0257b8af5 to your computer and use it in GitHub Desktop.
Simple copy stdin to stdout example using Rust tokio
extern crate futures;
extern crate tokio_core;
extern crate tokio_io;
extern crate tokio_file_unix;
use futures::{Future};
use tokio_io::io::copy;
use tokio_core::reactor::Core;
use std::io::{Result};
use std::os::unix::io::FromRawFd;
use tokio_file_unix::File as TokioFile;
fn run() -> Result<()> {
let mut core = Core::new()?;
let handle = core.handle();
let fd0_f : std::fs::File = unsafe{FromRawFd::from_raw_fd(0)};
let fd1_f : std::fs::File = unsafe{FromRawFd::from_raw_fd(1)};
let fd0 = TokioFile::new_nb(fd0_f)?.into_io(&handle)?;
let fd1 = TokioFile::new_nb(fd1_f)?.into_io(&handle)?;
core.run(copy(fd0, fd1).map(|_|{}))
}
fn main() {
run().unwrap()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment