1 use crate::sink::{SinkExt, SinkMapErr}; 2 use futures_core::stream::{Stream, FusedStream}; 3 use futures_sink::{Sink}; 4 use pin_project_lite::pin_project; 5 6 pin_project! { 7 /// Sink for the [`sink_err_into`](super::SinkExt::sink_err_into) method. 8 #[derive(Debug)] 9 #[must_use = "sinks do nothing unless polled"] 10 pub struct SinkErrInto<Si: Sink<Item>, Item, E> { 11 #[pin] 12 sink: SinkMapErr<Si, fn(Si::Error) -> E>, 13 } 14 } 15 16 impl<Si, E, Item> SinkErrInto<Si, Item, E> 17 where Si: Sink<Item>, 18 Si::Error: Into<E>, 19 { new(sink: Si) -> Self20 pub(super) fn new(sink: Si) -> Self { 21 Self { 22 sink: SinkExt::sink_map_err(sink, Into::into), 23 } 24 } 25 26 delegate_access_inner!(sink, Si, (.)); 27 } 28 29 impl<Si, Item, E> Sink<Item> for SinkErrInto<Si, Item, E> 30 where Si: Sink<Item>, 31 Si::Error: Into<E>, 32 { 33 type Error = E; 34 35 delegate_sink!(sink, Item); 36 } 37 38 // Forwarding impl of Stream from the underlying sink 39 impl<S, Item, E> Stream for SinkErrInto<S, Item, E> 40 where S: Sink<Item> + Stream, 41 S::Error: Into<E> 42 { 43 type Item = S::Item; 44 45 delegate_stream!(sink); 46 } 47 48 impl<S, Item, E> FusedStream for SinkErrInto<S, Item, E> 49 where S: Sink<Item> + FusedStream, 50 S::Error: Into<E> 51 { is_terminated(&self) -> bool52 fn is_terminated(&self) -> bool { 53 self.sink.is_terminated() 54 } 55 } 56