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
55
56
57
58
59
60
61
62
63
64
65
66
67
use effectful::{
    bound::{Bool, IsSend, IsSync},
    effective::{Effective, Canonical},
    environment::{Environment},
    DynBind,
    forward_send_sync,
};
use mockall::mock;
use treaty::{any::AnyTrait, build::BuilderTypes, protocol::DynVisitor, Builder, Walker};

mock! {
    pub Walker<Output, Error, E: Environment> {
        pub fn walk<'a, 'lt, 'ctx>(self, visitor: DynVisitor<'a, 'lt, 'ctx, E>) -> Result<Output, Error>;

        // pub fn traits(&self, id: TypeNameId) -> &Option<Box<dyn for<'ctx> AnyTrait<'ctx, E>>>;
        //
        // pub fn traits_mut(&mut self, id: TypeNameId) -> &mut Option<Box<dyn for<'ctx> AnyTrait<'ctx, E>>>;
    }
}

forward_send_sync!({Output, Error} {} {E: (Environment + Send)} MockWalker<Output, Error, E>);

impl<'ctx, Output: DynBind<E>, Error: DynBind<E> + core::fmt::Debug, E: Environment + Send> Walker<'ctx, E>
    for MockWalker<Output, Error, E>
{
    type Error = Error;

    type Output = Output;

    fn walk<'a: 'c, 'b: 'c, 'c>(
        self,
        visitor: DynVisitor<'a, 'b, 'ctx, E>,
    ) -> Canonical<'c, Result<Self::Output, Self::Error>, E>
    where
        Self: 'c,
    {
        E::value(self.walk(visitor)).cast()
    }
}

impl<'lt, 'ctx: 'lt, Output: DynBind<E> + 'lt, Error: DynBind<E> + 'lt, E: Environment> AnyTrait<'lt, 'ctx>
    for MockWalker<Output, Error, E>
{
    // fn upcast_to_id<'a>(
    //     &'a self,
    //     id: TypeNameId,
    // ) -> Option<AnyTraitObject<'a, 'ctx, indirect::Ref, E>>
    // where
    //     'ctx: 'a,
    // {
    //     self.traits(id).as_ref().and_then(|t| t.upcast_to_id(id))
    // }
    //
    // fn upcast_to_id_mut<'a>(
    //     &'a mut self,
    //     id: TypeNameId,
    // ) -> Option<AnyTraitObject<'a, 'ctx, indirect::Mut, E>>
    // where
    //     'ctx: 'a,
    // {
    //     self.traits_mut(id)
    //         .as_mut()
    //         .and_then(|t| t.upcast_to_id_mut(id))
    // }
    //
    // type Available = () where Self: Sized;
}