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
use crate::{Context, FieldResult};
#[async_trait::async_trait]
pub trait Guard {
#[allow(missing_docs)]
async fn check(&self, ctx: &Context<'_>) -> FieldResult<()>;
}
pub trait GuardExt: Guard + Sized {
fn and<R: Guard>(self, other: R) -> And<Self, R> {
And(self, other)
}
}
impl<T: Guard> GuardExt for T {}
pub struct And<A: Guard, B: Guard>(A, B);
#[async_trait::async_trait]
impl<A: Guard + Send + Sync, B: Guard + Send + Sync> Guard for And<A, B> {
async fn check(&self, ctx: &Context<'_>) -> FieldResult<()> {
self.0.check(ctx).await?;
self.1.check(ctx).await
}
}