Diffstat (limited to 'src/protocol/visitor/value.rs')
-rw-r--r--src/protocol/visitor/value.rs69
1 files changed, 35 insertions, 34 deletions
diff --git a/src/protocol/visitor/value.rs b/src/protocol/visitor/value.rs
index 447ad82..5a6a2d8 100644
--- a/src/protocol/visitor/value.rs
+++ b/src/protocol/visitor/value.rs
@@ -3,11 +3,7 @@
//! In some sense, this is the most basic protocol.
use crate::{
- any::{TypeName, WithContextLt},
- bijective_higher_ranked_type,
- effect::{Effect, Future},
- hkt::AnySizedSend,
- protocol::{walker::hint::HintMeta, Visitor},
+ any::{TypeName}, effect::{Effect, Future}, higher_ranked_type, hkt::Marker, protocol::{walker::hint::{HintKnown, HintMeta}, Visitor}
};
use super::VisitResult;
@@ -15,7 +11,7 @@ use super::VisitResult;
/// Trait object for the [`Value`] protocol.
///
/// Types implementing the [`Value`] protocol will implement this trait.
-pub trait Value<'ctx, T: WithContextLt::MemberType<'ctx>, E: Effect> {
+pub trait Value<'ctx, T: ?Sized + TypeName::MemberType, E: Effect> {
/// Visit a value of type `T`.
///
/// Use this to give a value to a visitor. Its expected that a walker
@@ -27,56 +23,61 @@ pub trait Value<'ctx, T: WithContextLt::MemberType<'ctx>, E: Effect> {
/// and error.
fn visit<'a>(
&'a mut self,
- value: WithContextLt::T<'a, 'ctx, T>,
- ) -> Future<'a, VisitResult<WithContextLt::T<'a, 'ctx, T>>, E>
+ value: TypeName::T<'a, 'ctx, T>,
+ ) -> Future<'a, VisitResult<TypeName::T<'a, 'ctx, T>>, E>
where
- WithContextLt::T<'a, 'ctx, T>: Send + Sized,
+ TypeName::T<'a, 'ctx, T>: Send + Sized,
'ctx: 'a;
}
-bijective_higher_ranked_type! {
- pub type DynValue['ctx][T, E][]: WithContextLt['ctx][]
- for<'a>
- (dyn Value<'ctx, T, E> + Send + 'a)
- where {
- E: Effect,
- T: ?Sized + WithContextLt::MemberType<'ctx> + 'ctx
- }
-}
+pub struct ValueProto<T: ?Sized + TypeName::MemberType, E: Effect>(Marker<(*const T, E)>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T, E] type T['a, 'ctx] for ValueProto<T, E> =
+ dyn Value<'ctx, T, E> + Send + 'a
+ where {
+ T: ?Sized + TypeName::MemberType,
+ E: Effect
+ };
-bijective_higher_ranked_type! {
- pub type [][E][T[][]]: TypeName[][]
- for<'ctx>
- (DynValue<'ctx, TypeName::T<'ctx, T>, E>)
- (DynValue<'ctx, T, E>)
- where {
- E: Effect,
- T: ?Sized,
+ impl['a, 'ctx, T, E] type HigherRanked['a, 'ctx] for dyn Value<'ctx, T, E> + Send + 'a =
+ ValueProto<T, E>
+ where {
+ T: ?Sized + TypeName::MemberType,
+ E: Effect
+ };
}
}
pub struct ValueKnown;
-bijective_higher_ranked_type! {
- pub type ValueKnownHkt[][]: AnySizedSend[][] for<'lt> (ValueKnown)
+higher_ranked_type! {
+ impl HintKnown {
+ impl['a] type T['a] for ValueKnown =
+ ValueKnown;
+
+ impl['a] type HigherRanked['a] for ValueKnown =
+ ValueKnown;
+ }
}
// This enrolls the Value protocol into the walker hint system.
-impl<'a, 'ctx: 'a, T, E: Effect> HintMeta<'ctx> for DynValue<'ctx, T, E> {
- type Known = ValueKnownHkt;
+impl<'a, 'ctx: 'a, T: TypeName::MemberType, E: Effect> HintMeta<'ctx> for ValueProto<T, E> {
+ type Known = ValueKnown;
type Hint = ();
}
-pub fn visit_value<'a, 'ctx, T: Send + WithContextLt::LowerType<'a, 'ctx> + 'ctx, E: Effect>(
+pub fn visit_value<'a, 'ctx, T: Send + TypeName::LowerType<'a, 'ctx>, E: Effect>(
visitor: Visitor<'a, 'ctx>,
value: T,
-) -> Future<'a, VisitResult<T>, E>
+) -> Future<'a, VisitResult<T>, E>
where
- WithContextLt::HigherRanked<'a, 'ctx, T>: TypeName::LowerType<'ctx> + Sized,
+ TypeName::HigherRanked<'a, 'ctx, T>: TypeName::MemberType
{
if let Some(object) =
- visitor.upcast_mut::<DynValue<'ctx, WithContextLt::HigherRanked<'a, 'ctx, T>, E>>()
+ visitor.upcast_mut::<ValueProto<TypeName::HigherRanked<'a, 'ctx, T>, E>>()
{
// Allow the visitor to give a hint if it wants.
object.visit(value)