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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use async_trait::async_trait;
use crate::acquire::acquire_with_resource_and_context::AcquireAttributeWithResourceAndContext;
use crate::attribute::{
    AsyncAttribute,
    SyncAttribute
};
use crate::chain::{ConstraintChain, ConstraintEntity, EntityTag};
use crate::DEFAULT_ELEMENT_TAG;
use crate::has::HasEntityWithType;

impl<T> AcquireAttribute for T
    where
        T: AcquireAttributeWithResourceAndContext<()>, {}

#[async_trait]
pub trait AcquireAttribute: AcquireAttributeWithResourceAndContext<()> {
    async fn prove_async<
        'ctx,
        Attr,
        const STAG: EntityTag,
    >(self) -> Result<ConstraintChain<STAG, DEFAULT_ELEMENT_TAG, Attr, Self>, Attr::Error>
        where
            Attr::Subject: ConstraintEntity + 'static,
            Self: HasEntityWithType<STAG, Attr::Subject>,
            Attr: AsyncAttribute<Resource = (), Context<'ctx> = ()>,
    {
        let subject = self.get_entity::<_, STAG>();

        Attr::test_async(subject, &(), ()).await?;

        Ok(ConstraintChain::<_, _, _, _>::new(self))
    }

    fn prove<
        'ctx,
        Attr,
        const STAG: EntityTag,
    >(self) -> Result<ConstraintChain<STAG, DEFAULT_ELEMENT_TAG, Attr, Self>, Attr::Error>
        where
            Attr::Subject: ConstraintEntity + 'static,
            Self: HasEntityWithType<STAG, Attr::Subject>,
            Attr: SyncAttribute<Resource = (), Context<'ctx> = ()>,
    {
        let subject = self.get_entity::<_, STAG>();

        Attr::test(subject, &(), ())?;

        Ok(ConstraintChain::<_, _, _, _>::new(self))
    }
}