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
use mockall::mock;
use treaty::{
    any::any_trait,
    effect::{Effect, Effective, ErasedEffective},
    protocol::visitor::{Tag, TagKind, TagProto, VisitResult},
    DynWalkerObjSafe,
};

mock! {
    pub TagVisitor<K: TagKind, E> {
        pub fn visit<'a, 'ctx>(&'a mut self, kind: K, walker: DynWalkerObjSafe<'a, 'ctx, E>) -> VisitResult<()>;
    }
}

any_trait! {
    impl['ctx, K, E] MockTagVisitor<K, E> = [
        TagProto<K, E>,
    ] where
        K: TagKind,
        E: Effect,
}

impl<'ctx, K: TagKind, E: Effect> Tag<'ctx, K, E> for MockTagVisitor<K, E> {
    fn visit<'a: 'c, 'b: 'c, 'c>(
        &'a mut self,
        kind: K,
        walker: DynWalkerObjSafe<'b, 'ctx, E>,
    ) -> ErasedEffective<'c, VisitResult<DynWalkerObjSafe<'b, 'ctx, E>>, E> {
        E::ready(match self.visit(kind, walker) {
            VisitResult::Skipped(_) => VisitResult::Skipped(walker),
            VisitResult::Control(flow) => VisitResult::Control(flow),
        })
        .into_erased()
    }
}