Diffstat (limited to 'tests/common/protocol/visitor.rs')
| -rw-r--r-- | tests/common/protocol/visitor.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/common/protocol/visitor.rs b/tests/common/protocol/visitor.rs new file mode 100644 index 0000000..a71e9ec --- /dev/null +++ b/tests/common/protocol/visitor.rs @@ -0,0 +1,31 @@ +use mockall::mock; +use treaty::{any::{any_trait, TypeName, WithContextLt}, effect::{Effect, Future}, protocol::visitor::value::{DynValue, Value}, Flow}; + +mock! { + pub ValueVisitor<T: for<'ctx> WithContextLt::MemberType<'ctx>, E> + where + for<'a, 'ctx> WithContextLt::T<'a, 'ctx, T>: Sized + { + pub fn visit<'a, 'ctx>(&'a mut self, value: WithContextLt::T<'a, 'ctx, T>) -> Flow; + } +} + +any_trait! { + impl['ctx, T, E] MockValueVisitor<T, E> = [ + DynValue<'ctx, T, E> + ] where + T: for<'lt> TypeName::LowerType<'lt> + 'ctx, + for<'a, 'lt> WithContextLt::T<'a, 'lt, T>: Sized, + E: Effect, +} + +impl<'ctx, T: for<'lt> WithContextLt::MemberType<'lt>, E: Effect> Value<'ctx, T, E> + for MockValueVisitor<T, E> +where + for<'a, 'lt> WithContextLt::T<'a, 'lt, T>: Sized, +{ + fn visit<'a>(&'a mut self, value: WithContextLt::T<'a, 'ctx, T>) -> Future<'a, Flow, E> + where 'ctx: 'a { + E::ready(self.visit(value)) + } +} |