use ConnectionError; use super::Frame; use futures::*; use bytes::BytesMut; use std::io; pub struct Reader { inner: T, } impl Stream for Reader where T: Stream, { type Item = Frame; type Error = ConnectionError; fn poll(&mut self) -> Poll, ConnectionError> { match try_ready!(self.inner.poll()) { Some(bytes) => { Frame::load(bytes.freeze()) .map(|frame| Async::Ready(Some(frame))) .map_err(ConnectionError::from) } None => Ok(Async::Ready(None)), } } } impl Sink for Reader { type SinkItem = T::SinkItem; type SinkError = T::SinkError; fn start_send(&mut self, item: T::SinkItem) -> StartSend { self.inner.start_send(item) } fn poll_complete(&mut self) -> Poll<(), T::SinkError> { self.inner.poll_complete() } }