a3s_boot/pipeline/
middleware.rs1use crate::{BootRequest, BootResponse, BoxFuture, Result};
2use std::future::Future;
3
4pub enum MiddlewareOutcome {
6 Continue(BootRequest),
7 Respond(BootResponse),
8}
9
10impl MiddlewareOutcome {
11 pub fn next(request: BootRequest) -> Self {
12 Self::Continue(request)
13 }
14
15 pub fn response(response: BootResponse) -> Self {
16 Self::Respond(response)
17 }
18}
19
20pub trait Middleware: Send + Sync + 'static {
22 fn handle(&self, request: BootRequest) -> BoxFuture<'static, Result<MiddlewareOutcome>>;
23}
24
25impl<F, Fut> Middleware for F
26where
27 F: Fn(BootRequest) -> Fut + Send + Sync + 'static,
28 Fut: Future<Output = Result<MiddlewareOutcome>> + Send + 'static,
29{
30 fn handle(&self, request: BootRequest) -> BoxFuture<'static, Result<MiddlewareOutcome>> {
31 Box::pin(self(request))
32 }
33}