use std::future::IntoFuture;
use crate::response::{IntoResponse, Response};
pub struct Next<C>
where
C: IntoFuture<Output = Response>,
{
request_pipeline: C,
}
pub enum Processing<T = Response>
where
T: IntoResponse,
{
Continue,
EarlyReturn(T),
}
impl<T: IntoResponse> Processing<T> {
pub fn into_response(self) -> Option<T> {
match self {
Processing::Continue => None,
Processing::EarlyReturn(response) => Some(response),
}
}
}
#[doc(hidden)]
pub async fn wrap_noop<C: IntoFuture<Output = Response>>(next: Next<C>) -> Response {
next.await
}
impl<C> Next<C>
where
C: IntoFuture<Output = Response>,
{
pub fn new(request_pipeline: C) -> Self {
Self { request_pipeline }
}
}
impl<C> IntoFuture for Next<C>
where
C: IntoFuture<Output = Response>,
{
type Output = Response;
type IntoFuture = <C as IntoFuture>::IntoFuture;
fn into_future(self) -> Self::IntoFuture {
self.request_pipeline.into_future()
}
}