1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::{Endpoint, Guard, Request};
pub struct GuardEndpoint<E, T> {
inner: E,
guard: T,
}
impl<E, T> GuardEndpoint<E, T> {
pub(crate) fn new(inner: E, guard: T) -> Self {
Self { guard, inner }
}
}
#[async_trait::async_trait]
impl<E, T> Endpoint for GuardEndpoint<E, T>
where
T: Guard,
E: Endpoint,
{
type Output = E::Output;
#[inline]
fn check(&self, req: &Request) -> bool {
if !self.guard.check(req) {
return false;
}
self.inner.check(req)
}
async fn call(&self, req: Request) -> Self::Output {
self.inner.call(req).await
}
}