use mockall::mock;
use treaty::{
any::{any_trait, TypeName},
effect::{Effect, Future},
protocol::visitor::{Value, ValueProto, 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,
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,
{
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) {
VisitResult::Skipped(_) => VisitResult::Skipped(value),
VisitResult::Control(flow) => VisitResult::Control(flow),
})
}
}