Created
October 9, 2017 19:15
-
-
Save vi/f4be6e945bb5a836edb15de0257b8af5 to your computer and use it in GitHub Desktop.
Simple copy stdin to stdout example using Rust tokio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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