Added a `Sink` implementation for where `stream::FromErr` also wraps a `Sink`.
Simplifies Client type of into Client<I, FromErr<C>>.
use core::marker::PhantomData;
-use {Stream, Poll, Async};
+use {Stream, Poll, Async, Sink, StartSend};
/// A stream combinator to change the error type of a stream.
///
@@ -33,3 +33,20 @@ impl<S: Stream, E: From<S::Error>> Stream for FromErr<S, E> {
e.map_err(From::from)
}
}
+
+impl<S: Stream + Sink, E: From<S::SinkError>> Sink for FromErr<S, E> {
+ type SinkItem = S::SinkItem;
+ type SinkError = E;
+
+ fn start_send(&mut self, item: Self::SinkItem) -> StartSend<Self::SinkItem, Self::SinkError> {
+ self.stream.start_send(item).map_err(|e| e.into())
+ }
+
+ fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
+ self.stream.poll_complete().map_err(|e| e.into())
+ }
+
+ fn close(&mut self) -> Poll<(), Self::SinkError> {
+ self.stream.close().map_err(|e| e.into())
+ }
+}
