Diffstat (limited to 'src/protocol/visitor/value.rs')
-rw-r--r--src/protocol/visitor/value.rs46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/protocol/visitor/value.rs b/src/protocol/visitor/value.rs
index 5628eac..a0c435c 100644
--- a/src/protocol/visitor/value.rs
+++ b/src/protocol/visitor/value.rs
@@ -16,7 +16,9 @@ use crate::{
/// Trait object for the [`Value`] protocol.
///
/// Types implementing the [`Value`] protocol will implement this trait.
-pub trait Value<'a, 'ctx: 'a, T, E: Effect<'ctx>> {
+pub trait Value<'a, 'ctx: 'a, T> {
+ type Effect: Effect<'ctx>;
+
/// Visit a value of type `T`.
///
/// Use this to give a value to a visitor. Its expected that a walker
@@ -26,19 +28,21 @@ pub trait Value<'a, 'ctx: 'a, T, E: Effect<'ctx>> {
/// If a [`ControlFlow::Break`] is returned then the walker
/// should stop walking as soon as possible as there has likely been
/// and error.
- fn visit(&'a mut self, value: T) -> Future<'a, 'ctx, ControlFlow<(), ()>, E>;
+ fn visit(&'a mut self, value: T) -> Future<'a, 'ctx, ControlFlow<(), ()>, Self::Effect>
+ where
+ Self: 'a;
}
nameable! {
pub struct Name['a, 'ctx, T, E];
- impl [T::Name, E] for dyn Value<'a, 'ctx, T, E> + 'a where {
+ impl [T::Name, E] for dyn Value<'a, 'ctx, T, Effect = E> + 'a where {
T: TypeNameable<'a, 'ctx> + ?Sized,
E: Effect<'ctx>,
'ctx: 'a,
}
- impl [T, E] where dyn Value<'a, 'ctx, T::Nameable, E> + 'a {
+ impl [T, E] where dyn Value<'a, 'ctx, T::Nameable, Effect = E> + 'a {
T: TypeName<'a, 'ctx> + ?Sized,
E: Effect<'ctx>,
'ctx: 'a,
@@ -50,7 +54,7 @@ higher_ranked_type! {
}
// This enrolls the Value protocol into the walker hint system.
-impl<'a, 'ctx: 'a, T, E: Effect<'ctx>> HintMeta<'ctx> for dyn Value<'a, 'ctx, T, E> + 'a {
+impl<'a, 'ctx: 'a, T, E: Effect<'ctx>> HintMeta<'ctx> for dyn Value<'a, 'ctx, T, Effect = E> + 'a {
type Known = Known<'ctx>;
type Hint = ();
@@ -75,10 +79,12 @@ mod test {
fn visit() {
struct Visitor<E>(Option<i32>, PhantomData<fn() -> E>);
- impl<'a, 'ctx: 'a, E> Value<'a, 'ctx, OwnedStatic<i32>, E> for Visitor<E>
+ impl<'a, 'ctx: 'a, E> Value<'a, 'ctx, OwnedStatic<i32>> for Visitor<E>
where
E: Effect<'ctx>,
{
+ type Effect = E;
+
fn visit(
&'a mut self,
OwnedStatic(value): OwnedStatic<i32>,
@@ -90,10 +96,12 @@ mod test {
}
}
- impl<'a, 'ctx: 'a, E> Value<'a, 'ctx, BorrowedStatic<'ctx, i32>, E> for Visitor<E>
+ impl<'a, 'ctx: 'a, E> Value<'a, 'ctx, BorrowedStatic<'ctx, i32>> for Visitor<E>
where
E: Effect<'ctx>,
{
+ type Effect = E;
+
fn visit(
&'a mut self,
BorrowedStatic(value): BorrowedStatic<'ctx, i32>,
@@ -107,8 +115,8 @@ mod test {
any_trait! {
impl['a, 'ctx, E] Visitor<E> = [
- dyn Value<'a, 'ctx, OwnedStatic<i32>, E> + 'a,
- dyn Value<'a, 'ctx, BorrowedStatic<'ctx, i32>, E> + 'a,
+ dyn Value<'a, 'ctx, OwnedStatic<i32>, Effect = E> + 'a,
+ dyn Value<'a, 'ctx, BorrowedStatic<'ctx, i32>, Effect = E> + 'a,
] where E: Effect<'ctx>,
}
@@ -116,7 +124,7 @@ mod test {
let object: &mut (dyn AnyTrait<'_> + Send) = &mut v;
Spin::block_on(
object
- .upcast_mut::<dyn Value<'_, '_, OwnedStatic<i32>, Blocking>>()
+ .upcast_mut::<dyn Value<'_, '_, OwnedStatic<i32>, Effect = Blocking>>()
.unwrap()
.visit(OwnedStatic(42)),
);
@@ -126,7 +134,7 @@ mod test {
let object: &mut (dyn AnyTrait<'_> + Send) = &mut v;
Spin::block_on(
object
- .upcast_mut::<dyn Value<'_, '_, BorrowedStatic<'_, i32>, Blocking>>()
+ .upcast_mut::<dyn Value<'_, '_, BorrowedStatic<'_, i32>, Effect = Blocking>>()
.unwrap()
.visit(BorrowedStatic(&101)),
);
@@ -138,10 +146,12 @@ mod test {
fn visit_borrowed() {
struct Visitor<'ctx, E>(Option<&'ctx mut String>, PhantomData<fn() -> E>);
- impl<'a, 'ctx: 'a, E> Value<'a, 'ctx, BorrowedMutStatic<'ctx, String>, E> for Visitor<'ctx, E>
+ impl<'a, 'ctx: 'a, E> Value<'a, 'ctx, BorrowedMutStatic<'ctx, String>> for Visitor<'ctx, E>
where
E: Effect<'ctx>,
{
+ type Effect = E;
+
fn visit(
&'a mut self,
BorrowedMutStatic(value): BorrowedMutStatic<'ctx, String>,
@@ -156,7 +166,7 @@ mod test {
any_trait! {
impl['a, 'ctx, E] Visitor<'ctx, E> = [
- dyn Value<'a, 'ctx, BorrowedMutStatic<'ctx, String>, E> + 'a,
+ dyn Value<'a, 'ctx, BorrowedMutStatic<'ctx, String>, Effect = E> + 'a,
] where E: Effect<'ctx>
}
@@ -166,7 +176,7 @@ mod test {
let object: &mut (dyn AnyTrait<'_> + Send) = &mut v;
Spin::block_on(
object
- .upcast_mut::<dyn Value<'_, '_, _, Blocking>>()
+ .upcast_mut::<dyn Value<'_, '_, _, Effect = Blocking>>()
.unwrap()
.visit(BorrowedMutStatic(&mut y)),
);
@@ -179,10 +189,12 @@ mod test {
fn visit_borrowed_unsized() {
struct Visitor<'ctx, E>(Option<&'ctx str>, PhantomData<fn() -> E>);
- impl<'a, 'ctx: 'a, E> Value<'a, 'ctx, BorrowedStatic<'ctx, str>, E> for Visitor<'ctx, E>
+ impl<'a, 'ctx: 'a, E> Value<'a, 'ctx, BorrowedStatic<'ctx, str>> for Visitor<'ctx, E>
where
E: Effect<'ctx>,
{
+ type Effect = E;
+
fn visit(
&'a mut self,
BorrowedStatic(value): BorrowedStatic<'ctx, str>,
@@ -196,7 +208,7 @@ mod test {
any_trait! {
impl['a, 'ctx, E] Visitor<'ctx, E> = [
- dyn Value<'a, 'ctx, BorrowedStatic<'ctx, str>, E> + 'a,
+ dyn Value<'a, 'ctx, BorrowedStatic<'ctx, str>, Effect = E> + 'a,
] where E: Effect<'ctx>
}
@@ -206,7 +218,7 @@ mod test {
let object: &mut (dyn AnyTrait<'_> + Send) = &mut v;
Spin::block_on(
object
- .upcast_mut::<dyn Value<'_, '_, BorrowedStatic<'_, str>, Blocking> + '_>()
+ .upcast_mut::<dyn Value<'_, '_, BorrowedStatic<'_, str>, Effect = Blocking> + '_>()
.unwrap()
.visit(BorrowedStatic(&y)),
);