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
use mockall::mock;
use treaty::{
    any::{any_trait, TypeName},
    effect::{Effect, Future},
    protocol::visitor::{ValueProto, Value, VisitResult},
    Flow,
};

mock! {
    pub ValueVisitor<T: TypeName::MemberType, E>
    where
        for<'a, 'ctx> TypeName::T<'a, 'ctx, T>: Sized
    {
        pub fn visit<'a, 'ctx>(&'a mut self, value: TypeName::T<'a, 'ctx, T>) -> VisitResult<()>;
    }
}

any_trait! {
    impl['ctx, T, E] MockValueVisitor<T, E> = [
        ValueProto<T, E>
    ] where
        T: TypeName::MemberType + Send,
        for<'a, 'b> TypeName::T<'a, 'b, T>: Clone + Sized,
        E: Effect,
}

impl<'ctx, T: TypeName::MemberType, E: Effect> Value<'ctx, T, E>
    for MockValueVisitor<T, E>
where
    for<'a, 'lt> TypeName::T<'a, 'lt, T>: Sized + Clone,
{
    fn visit<'a>(
        &'a mut self,
        value: TypeName::T<'a, 'ctx, T>,
    ) -> Future<'a, VisitResult<TypeName::T<'a, 'ctx, T>>, E>
    where
        TypeName::T<'a, 'ctx, T>: Send,
        'ctx: 'a,
    {
        E::ready(match self.visit(value.clone()) {
            VisitResult::Skipped(_) => VisitResult::Skipped(value),
            VisitResult::Control(flow) => VisitResult::Control(flow),
        })
    }
}