futures_util/sink/
err_into.rsuse futures_core::{Stream, Poll};
use futures_core::task;
use futures_sink::{Sink};
use sink::{SinkExt, SinkMapErr};
#[derive(Clone, Debug)]
#[must_use = "futures do nothing unless polled"]
pub struct SinkErrInto<S: Sink, E> {
sink: SinkMapErr<S, fn(S::SinkError) -> E>,
}
pub fn new<S, E>(sink: S) -> SinkErrInto<S, E>
where S: Sink,
S::SinkError: Into<E>
{
SinkErrInto {
sink: SinkExt::sink_map_err(sink, Into::into),
}
}
impl<S: Sink, E> SinkErrInto<S, E> {
pub fn get_ref(&self) -> &S {
self.sink.get_ref()
}
pub fn get_mut(&mut self) -> &mut S {
self.sink.get_mut()
}
pub fn into_inner(self) -> S {
self.sink.into_inner()
}
}
impl<S, E> Sink for SinkErrInto<S, E>
where S: Sink,
S::SinkError: Into<E>,
{
type SinkItem = S::SinkItem;
type SinkError = E;
delegate_sink!(sink);
}
impl<S: Sink + Stream, E> Stream for SinkErrInto<S, E> {
type Item = S::Item;
type Error = S::Error;
fn poll_next(&mut self, cx: &mut task::Context) -> Poll<Option<S::Item>, S::Error> {
self.sink.poll_next(cx)
}
}