use crate::futures::BoxFuture;
use crate::Request;
#[cfg(feature = "streams")]
use {crate::futures::Stream, crate::StreamRequest};
pub trait Interceptor<Req, Res>
where
Req: Request<Res>,
{
fn handle(&mut self, req: Req, next: Box<dyn FnOnce(Req) -> Res>) -> Res;
}
#[cfg(feature = "streams")]
pub trait StreamInterceptor {
type Request: StreamRequest<Stream = Self::Stream, Item = Self::Item>;
type Stream: Stream<Item = Self::Item>;
type Item;
fn handle_stream(
&mut self,
req: Self::Request,
next: Box<dyn FnOnce(Self::Request) -> Self::Stream>,
) -> Self::Stream;
}
#[cfg(feature = "async")]
#[cfg_attr(feature = "async", async_trait::async_trait)]
pub trait AsyncInterceptor<Req, Res>
where
Req: Request<Res> + Send,
{
async fn handle(
&mut self,
req: Req,
next: Box<dyn FnOnce(Req) -> BoxFuture<'static, Res> + Send>,
) -> Res;
}
#[cfg(all(feature = "async", feature = "streams"))]
#[cfg_attr(feature = "async", async_trait::async_trait)]
pub trait AsyncStreamInterceptor {
type Request: StreamRequest<Stream = Self::Stream, Item = Self::Item>;
type Stream: Stream<Item = Self::Item>;
type Item;
async fn handle_stream(
&mut self,
req: Self::Request,
next: Box<dyn FnOnce(Self::Request) -> BoxFuture<'static, Self::Stream> + Send>,
) -> Self::Stream;
}