Diffstat (limited to 'tests/common/protocol/value.rs')
| -rw-r--r-- | tests/common/protocol/value.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/common/protocol/value.rs b/tests/common/protocol/value.rs new file mode 100644 index 0000000..b0f2273 --- /dev/null +++ b/tests/common/protocol/value.rs @@ -0,0 +1,44 @@ +use mockall::mock; +use treaty::{ + any::{any_trait, TypeName}, + effect::{Effect, Effective, ErasedEffective}, + 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>: 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>, + ) -> ErasedEffective<'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), + }) + } +} |