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
51
52
53
54
use mockall::mock;
use treaty::{
    any::{any_trait, TypeName},
    effect::{Effect, Effective, ErasedEffective},
    protocol::{
        visitor::{DynRecoverableScope, Recoverable, RecoverableProto, RecoverableScope},
        DynWalker,
    },
    protocol::{
        visitor::{
            DynSequenceScope, RequestHint, RequestHintProto, Sequence, SequenceProto,
            SequenceScope, Value, ValueProto, VisitResult,
        },
        DynVisitor,
    },
    Flow, Status,
};

mock! {
    pub RecoverableVisitor<E> {
        pub fn visit<'a, 'ctx>(&mut self, scope: DynRecoverableScope<'a, 'ctx, E>) -> VisitResult;
    }
}

any_trait! {
    impl['ctx, E] MockRecoverableVisitor<E> = [
        RecoverableProto<E>
    ] where
        E: Effect,
}

impl<'ctx, E: Effect> Recoverable<'ctx, E> for MockRecoverableVisitor<E> {
    fn visit<'a>(
        &'a mut self,
        scope: DynRecoverableScope<'a, 'ctx, E>,
    ) -> ErasedEffective<'a, VisitResult, E> {
        E::ready(self.visit(scope))
    }
}

mock! {
    pub RecoverableScopeVisitor<E> {
        pub fn new_walk<'a, 'b, 'ctx>(&'a mut self, visitor: DynVisitor<'b, 'ctx>) -> Status;
    }
}

impl<'ctx, E: Effect> RecoverableScope<'ctx, E> for MockRecoverableScopeVisitor<E> {
    fn new_walk<'a: 'c, 'b: 'c, 'c>(
        &'a mut self,
        visitor: DynVisitor<'b, 'ctx>,
    ) -> ErasedEffective<'c, Status, E> {
        E::ready(self.new_walk(visitor))
    }
}