use crate::error::Error; use futures_util::stream::Stream; use std::{ marker::PhantomData, pin::Pin, task::{Context, Poll}, }; pin_project_lite::pin_project! { pub(super) struct MapError { #[pin] inner: S, _error: PhantomData, } } pub(super) fn map_crate_error(inner: S) -> MapError { map_error(inner) } pub(super) fn map_error(inner: S) -> MapError { MapError { inner, _error: PhantomData, } } impl Stream for MapError where S: Stream>, E: From, { type Item = Result; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let this = self.as_mut().project(); this.inner .poll_next(cx) .map(|opt| opt.map(|res| res.map_err(Into::into))) } }