diff --git a/src/io/mod.rs b/src/io/mod.rs index ecf004b4d..3e44a6b4e 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -43,7 +43,7 @@ pub use self::copy::{copy, Copy}; pub use self::flush::{flush, Flush}; pub use self::read_exact::{read_exact, ReadExact}; pub use self::read_to_end::{read_to_end, ReadToEnd}; -pub use self::read::{read, ReadSome}; +pub use self::read::read; pub use self::split::{ReadHalf, WriteHalf}; pub use self::window::Window; pub use self::write_all::{write_all, WriteAll}; diff --git a/src/io/read.rs b/src/io/read.rs index 07d5d87f8..91cfbe284 100644 --- a/src/io/read.rs +++ b/src/io/read.rs @@ -1,7 +1,6 @@ use std::mem; -use std::io::Read; -use futures::{Async, Future, Poll}; +use futures::{Future, Poll}; enum State { Pending { @@ -16,23 +15,23 @@ enum State { /// /// The returned future will resolve to both the I/O stream as well as the /// buffer once the read operation is completed. -pub fn read(rd: R, buf: T) -> ReadSome - where R: Read, +pub fn read(rd: R, buf: T) -> Read + where R: ::std::io::Read, T: AsMut<[u8]> { - ReadSome { state: State::Pending { rd: rd, buf: buf } } + Read { state: State::Pending { rd: rd, buf: buf } } } /// A future which can be used to easily read available number of bytes to fill /// a buffer. /// /// Created by the [`read`] function. -pub struct ReadSome { +pub struct Read { state: State, } -impl Future for ReadSome - where R: Read, +impl Future for Read + where R: ::std::io::Read, T: AsMut<[u8]> { type Item = (R, T, usize); @@ -40,17 +39,7 @@ impl Future for ReadSome fn poll(&mut self) -> Poll<(R, T, usize), ::std::io::Error> { let nread = match self.state { - State::Pending { ref mut rd, ref mut buf } => { - let buf = buf.as_mut(); - - match rd.read(&mut buf[..]) { - Ok(nread) => nread, - Err(ref err) if err.kind() == ::std::io::ErrorKind::WouldBlock => { - return Ok(Async::NotReady) - } - Err(err) => return Err(err.into()), - } - } + State::Pending { ref mut rd, ref mut buf } => try_nb!(rd.read(&mut buf.as_mut()[..])), State::Empty => panic!("poll a ReadSome after it's done"), };