diff --git a/Cargo.toml b/Cargo.toml index 3a242f5..ec49692 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,12 +20,11 @@ default = ["libudev"] libudev = ["mio-serial/libudev"] [dependencies] -futures = "0.1" -tokio-io = "0.1" -tokio-reactor = "0.1" +tokio-io = "=0.2.0-alpha.1" +tokio-reactor = "=0.2.0-alpha.1" bytes = "0.4" mio = "0.6" mio-serial = { version = "=3.2.14", default-features = false } [dev-dependencies] -tokio = "0.1" +tokio = "=0.2.0-alpha.1" diff --git a/examples/serial_println.rs b/examples/serial_println.rs index 05e2f73..da05616 100644 --- a/examples/serial_println.rs +++ b/examples/serial_println.rs @@ -1,15 +1,13 @@ extern crate bytes; -extern crate futures; extern crate tokio; extern crate tokio_io; extern crate tokio_serial; -use std::{env, io, str}; -use tokio_io::codec::{Decoder, Encoder}; - use bytes::BytesMut; +use std::{env, io, str}; +use tokio::codec::{Decoder, Encoder}; -use futures::{Future, Stream}; +use tokio::prelude::*; #[cfg(unix)] const DEFAULT_TTY: &str = "/dev/ttyUSB0"; @@ -54,13 +52,16 @@ fn main() { port.set_exclusive(false) .expect("Unable to set serial port exlusive"); - let (_, reader) = LineCodec.framed(port).split(); + let framed = LineCodec.framed(port); - let printer = reader - .for_each(|s| { - println!("{:?}", s); - Ok(()) - }).map_err(|e| eprintln!("{}", e)); + let printer = framed.for_each(|s| { + match s { + Ok(data) => println!("{:x?}", data), + Err(err) => println!("err: {:x?}", err), + } + tokio::future::ready(()) + }); - tokio::run(printer); + let rt = tokio::runtime::Runtime::new().unwrap(); + rt.block_on(printer); } diff --git a/src/lib.rs b/src/lib.rs index 51833d0..b0c6b46 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,6 @@ #![deny(missing_docs)] extern crate bytes; -extern crate futures; extern crate tokio_io; extern crate tokio_reactor; @@ -15,18 +14,21 @@ extern crate mio_serial; // Re-export serialport types and traits from mio_serial pub use mio_serial::{ - DataBits, Error, ErrorKind, FlowControl, Parity, SerialPort, SerialPortSettings, StopBits, ClearBuffer, + ClearBuffer, DataBits, Error, ErrorKind, FlowControl, Parity, SerialPort, SerialPortSettings, + StopBits, }; /// A type for results generated by interacting with serial ports. pub type Result = mio_serial::Result; -use futures::{Async, Poll}; use tokio_io::{AsyncRead, AsyncWrite}; use tokio_reactor::{Handle, PollEvented}; +use bytes::Buf; use std::io::{self, Read, Write}; use std::path::Path; +use std::pin::Pin; +use std::task::{Context, Poll}; use std::time::Duration; /// Serial port I/O struct. @@ -227,24 +229,24 @@ impl ::SerialPort for Serial { self.io.get_ref().clear(buffer_to_clear) } - fn try_clone(&self) -> ::Result> { + fn try_clone(&self) -> ::Result> { self.io.get_ref().try_clone() } } impl Read for Serial { fn read(&mut self, buf: &mut [u8]) -> io::Result { - self.io.read(buf) + self.io.get_ref().read(buf) } } impl Write for Serial { fn write(&mut self, buf: &[u8]) -> io::Result { - self.io.write(buf) + self.io.get_ref().write(buf) } fn flush(&mut self) -> io::Result<()> { - self.io.flush() + self.io.get_ref().flush() } } @@ -258,17 +260,46 @@ impl AsRawFd for Serial { } impl AsyncRead for Serial { - fn poll_read(&mut self, buf: &mut [u8]) -> io::Result> { - self.io.poll_read(buf) + fn poll_read( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + buf: &mut [u8], + ) -> Poll> { + Pin::new(&mut self.get_mut().io).poll_read(cx, buf) } } impl AsyncWrite for Serial { - fn poll_write(&mut self, buf: &[u8]) -> io::Result> { - self.io.poll_write(buf) + fn poll_write( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + buf: &[u8], + ) -> Poll> { + Pin::new(&mut self.get_mut().io).poll_write(cx, buf) + } + + fn poll_shutdown( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll> { + Pin::new(&mut self.get_mut().io).poll_shutdown(cx) + } + + fn poll_write_buf( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + buf: &mut B, + ) -> Poll> + where + Self: Sized, + { + Pin::new(&mut self.get_mut().io).poll_write_buf(cx, buf) } - fn shutdown(&mut self) -> Poll<(), io::Error> { - self.io.shutdown() + fn poll_flush( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll> { + Pin::new(&mut self.get_mut().io).poll_flush(cx) } }