use crate::operator::then::Then;
use core::future::Future;
use core::marker::PhantomData;
use core::task::{Context, Poll};
#[cfg(feature = "tower")]
pub mod tower;
pub mod next;
pub mod and_then;
pub mod map_err;
pub use next::{next, Next};
#[cfg(feature = "tower")]
pub use tower::{ServiceOp, ServiceOperator};
use self::map_err::MapErr;
pub trait AsyncOperator<I> {
type Output;
type Error;
type Future<'a>: Future<Output = Result<Self::Output, Self::Error>>
where
Self: 'a;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
fn next(&mut self, input: I) -> Self::Future<'_>;
}
pub trait AsyncOperatorExt<I>: AsyncOperator<I> {
fn and_then<P2>(self, other: P2) -> Then<I, Self, P2>
where
Self: Sized,
P2: AsyncOperator<Self::Output>,
{
Then(self, other, PhantomData)
}
fn map_err<E, F>(self, f: F) -> MapErr<F, Self>
where
Self: Sized,
F: FnMut(Self::Error) -> E,
{
MapErr { inner: self, f }
}
}
impl<I, P> AsyncOperatorExt<I> for P where P: AsyncOperator<I> {}