Skip to main content

a3s_boot/pipeline/
guard.rs

1use super::ExecutionContext;
2use crate::{BoxFuture, Result};
3
4/// Decides whether a route handler can run.
5pub trait Guard: Send + Sync + 'static {
6    fn can_activate(&self, context: ExecutionContext) -> BoxFuture<'static, Result<bool>>;
7}
8
9impl<F, Fut> Guard for F
10where
11    F: Fn(ExecutionContext) -> Fut + Send + Sync + 'static,
12    Fut: std::future::Future<Output = Result<bool>> + Send + 'static,
13{
14    fn can_activate(&self, context: ExecutionContext) -> BoxFuture<'static, Result<bool>> {
15        Box::pin(self(context))
16    }
17}