a3s-boot 0.1.0

Adapter-first modular Rust web framework for A3S inspired by Nest.js
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use super::ExecutionContext;
use crate::{BoxFuture, Result};

/// Decides whether a route handler can run.
pub trait Guard: Send + Sync + 'static {
    fn can_activate(&self, context: ExecutionContext) -> BoxFuture<'static, Result<bool>>;
}

impl<F, Fut> Guard for F
where
    F: Fn(ExecutionContext) -> Fut + Send + Sync + 'static,
    Fut: std::future::Future<Output = Result<bool>> + Send + 'static,
{
    fn can_activate(&self, context: ExecutionContext) -> BoxFuture<'static, Result<bool>> {
        Box::pin(self(context))
    }
}