diff --git a/src/io/mod.rs b/src/io/mod.rs index 6d1341c05..22f57f5f4 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -44,7 +44,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; +pub use self::read::{read, ReadOnce}; pub use self::read_until::{read_until, ReadUntil}; pub use self::split::{ReadHalf, WriteHalf}; pub use self::window::Window; diff --git a/src/io/read.rs b/src/io/read.rs index 51bf9667f..d74f219cf 100644 --- a/src/io/read.rs +++ b/src/io/read.rs @@ -1,3 +1,4 @@ +use std::io::{Error, Read}; use std::mem; use futures::{Future, Poll}; @@ -15,32 +16,32 @@ enum State { /// /// The returned future will resolve to both the I/O stream and the buffer /// as well as the number of bytes read once the read operation is completed. -pub fn read(rd: R, buf: T) -> Read - where R: ::std::io::Read, +pub fn read(rd: R, buf: T) -> ReadOnce + where R: Read, T: AsMut<[u8]> { - Read { state: State::Pending { rd: rd, buf: buf } } + ReadOnce { 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 Read { +pub struct ReadOnce { state: State, } -impl Future for Read - where R: ::std::io::Read, +impl Future for ReadOnce + where R: Read, T: AsMut<[u8]> { type Item = (R, T, usize); - type Error = ::std::io::Error; + type Error = Error; - fn poll(&mut self) -> Poll<(R, T, usize), ::std::io::Error> { + fn poll(&mut self) -> Poll<(R, T, usize), Error> { let nread = match self.state { State::Pending { ref mut rd, ref mut buf } => try_nb!(rd.read(&mut buf.as_mut()[..])), - State::Empty => panic!("poll a Read after it's done"), + State::Empty => panic!("poll a ReadOnce after it's done"), }; match mem::replace(&mut self.state, State::Empty) {