simplified the higher ranked types
Konnor Andrews 2024-04-14
parent 0a6381b · commit 14710db
-rw-r--r--src/any.rs214
-rw-r--r--src/any/static_wrapper.rs145
-rw-r--r--src/any/type_name_id.rs72
-rw-r--r--src/build/builders/core/bool.rs4
-rw-r--r--src/build/builders/debug.rs19
-rw-r--r--src/effect.rs92
-rw-r--r--src/hkt.rs430
-rw-r--r--src/lib.rs12
-rw-r--r--src/protocol/visitor/recoverable.rs53
-rw-r--r--src/protocol/visitor/request_hint.rs35
-rw-r--r--src/protocol/visitor/sequence.rs51
-rw-r--r--src/protocol/visitor/tag.rs58
-rw-r--r--src/protocol/visitor/value.rs69
-rw-r--r--src/protocol/walker/hint.rs54
-rw-r--r--src/walk/walkers/core/struct.rs104
-rw-r--r--src/walk/walkers/core/tag.rs4
-rw-r--r--tests/common/protocol/tag.rs4
-rw-r--r--tests/common/protocol/visitor.rs26
-rw-r--r--tests/walkers/core/struct.rs8
19 files changed, 539 insertions, 915 deletions
diff --git a/src/any.rs b/src/any.rs
index 488f6f3..3207f02 100644
--- a/src/any.rs
+++ b/src/any.rs
@@ -6,7 +6,7 @@ pub mod indirect;
mod static_wrapper;
mod type_name_id;
-use crate::{bijective_higher_ranked_trait, bijective_higher_ranked_type, hkt::Invariant};
+use crate::{higher_ranked_trait, higher_ranked_type, hkt::{Invariant, Marker}};
use core::marker::PhantomData;
pub use static_wrapper::*;
@@ -15,100 +15,70 @@ pub use type_name_id::*;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::boxed::Box;
-bijective_higher_ranked_trait! {
- /// Higher ranked types with a context `'ctx` lifetime.
- ///
- /// Its recommended to name types of this class with a `Dyn` prefix.
- /// This prefix was chosen because most lower types used in treaty are trait objects.
- ///
- /// This is most important for trait objects. For example `dyn MyTrait<'ctx> + 'a` this
- /// type has a "extra" `'a` lifetime for how long its valid for. This higher ranked type class
- /// allows naming the trait object type without a `'a` being given.
- pub type class WithContextLt['ctx][]: {} [for<'a>]
-}
+higher_ranked_trait! {
+ pub type class TypeName for<'a, 'ctx> {
+ type Bound = &'a &'ctx ();
-bijective_higher_ranked_trait! {
- /// Higher ranked types that are `'static`.
- ///
- /// Types of this class can usually be sealed as they don't need to be named directly.
- ///
- /// Higher ranked types of this form have a [`TypeId`][core::any::TypeId] associated with them.
- /// This allows them to be used as a name for lifetime containing types.
- ///
- /// This type class has members in the [`WithContextLt`] higher ranked type class.
- /// To get a concrete type two lowerings need to be applied to inject two lifetimes.
- /// One for the context lifetime, and one for the lifetime of the concrete type.
- pub type class TypeName[][]: {'static} [for<'ctx> WithContextLt::MemberType<'ctx>]
-}
+ type T: { } where {
+ 'ctx: 'a
+ };
-bijective_higher_ranked_type! {
- /// Higher ranked type for borrows `&T`.
- ///
- /// The borrow gets the `'a` lifetime, not the `'ctx` lifetime.
- pub type DynRef['ctx][][T['ctx][]]: WithContextLt['ctx][]
- for<'a>
- (&'a WithContextLt::T<'a, 'ctx, T>)
- (&'a T)
- where {
- T: ?Sized
+ type HigherRanked: { 'static };
}
}
-bijective_higher_ranked_type! {
- pub type [][][T[][]]: TypeName[][]
- for<'ctx>
- (DynRef<'ctx, TypeName::T<'ctx, T>>)
- (DynRef<'ctx, T>)
- where {
- T: ?Sized
+pub struct RefHrt<T: ?Sized>(Marker<T>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for RefHrt<T> =
+ &'a TypeName::T<'a, 'ctx, T>
+ where {
+ T: ?Sized + TypeName::LowerForLt<'a, 'ctx, TypeName::Bound<'a, 'ctx>>,
+ TypeName::T<'a, 'ctx, T>: 'a
+ };
+
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for &'a T =
+ RefHrt<TypeName::HigherRanked<'a, 'ctx, T>>
+ where {
+ T: ?Sized + TypeName::LowerType<'a, 'ctx>
+ };
}
}
-bijective_higher_ranked_type! {
- /// Higher ranked type for mutable borrows `&mut T`.
- ///
- /// The borrow gets the `'a` lifetime, not the `'ctx` lifetime.
- pub type DynMut['ctx][][T['ctx][]]: WithContextLt['ctx][]
- for<'a>
- (&'a mut WithContextLt::T<'a, 'ctx, T>)
- (&'a mut T)
- where {
- T: ?Sized
- }
-}
-
-bijective_higher_ranked_type! {
- pub type [][][T[][]]: TypeName[][]
- for<'ctx>
- (DynMut<'ctx, TypeName::T<'ctx, T>>)
- (DynMut<'ctx, T>)
- where {
- T: ?Sized
+pub struct MutHrt<T: ?Sized>(Marker<T>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for MutHrt<T> =
+ &'a mut TypeName::T<'a, 'ctx, T>
+ where {
+ T: ?Sized + TypeName::LowerForLt<'a, 'ctx, TypeName::Bound<'a, 'ctx>>,
+ TypeName::T<'a, 'ctx, T>: 'a
+ };
+
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for &'a mut T =
+ MutHrt<TypeName::HigherRanked<'a, 'ctx, T>>
+ where {
+ T: ?Sized + TypeName::LowerType<'a, 'ctx>
+ };
}
}
#[cfg(feature = "alloc")]
-bijective_higher_ranked_type! {
- /// Higher ranked type for boxes `Box<T>`.
- ///
- /// A [`Box`] doesn't need either lifetime.
- pub type DynBox['ctx][][T['ctx][]]: WithContextLt['ctx][]
- for<'a>
- (Box<WithContextLt::T<'a, 'ctx, T>>)
- (Box<T>)
- where {
- T: ?Sized
- }
-}
-
-#[cfg(feature = "alloc")]
-bijective_higher_ranked_type! {
- pub type [][][T[][]]: TypeName[][]
- for<'ctx>
- (DynBox<'ctx, TypeName::T<'ctx, T>>)
- (DynBox<'ctx, T>)
- where {
- T: ?Sized
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for Box<T> =
+ Box<TypeName::T<'a, 'ctx, T>>
+ where {
+ T: ?Sized + TypeName::LowerForLt<'a, 'ctx, TypeName::Bound<'a, 'ctx>>,
+ };
+
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for Box<T> =
+ Box<TypeName::HigherRanked<'a, 'ctx, T>>
+ where {
+ T: ?Sized + TypeName::LowerType<'a, 'ctx>
+ };
}
}
@@ -119,8 +89,8 @@ bijective_higher_ranked_type! {
/// by `id` if [`AnyTrait`] had every trait as a super bound.
///
/// ```
-/// use treaty::any::{AnyTrait, any_trait, WithContextLt, TypeName};
-/// use treaty::hkt::bijective_higher_ranked_type;
+/// use treaty::any::{AnyTrait, any_trait, TypeName};
+/// use treaty::hkt::higher_ranked_type;
///
/// // Create a test value.
/// let my_num = MyNum(42);
@@ -141,15 +111,16 @@ bijective_higher_ranked_type! {
/// fn num(&self) -> i32;
/// }
///
-/// bijective_higher_ranked_type! {
-/// for['ctx] type DynToNum[][]: WithContextLt['ctx][]
-/// for<'a> (dyn ToNum + 'a)
-/// }
+/// enum DynToNum {}
+///
+/// higher_ranked_type! {
+/// impl TypeName {
+/// impl['a, 'ctx] type T['a, 'ctx] for DynToNum =
+/// dyn ToNum + 'a;
///
-/// // Make the trait object nameable.
-/// bijective_higher_ranked_type! {
-/// type [][]: TypeName[][]
-/// for<'ctx> (DynToNum)
+/// impl['a, 'ctx] type HigherRanked['a, 'ctx] for dyn ToNum + 'a =
+/// DynToNum;
+/// }
/// }
///
/// // An example struct.
@@ -206,9 +177,9 @@ impl<'b, 'ctx: 'b> dyn AnyTrait<'ctx> + Send + 'b {
/// as it automatically downcasts the returned [`AnyTraitObject`].
///
/// If the returned [`AnyTraitObject`] is the wrong type, then a panic happens.
- pub fn upcast<'a, Trait: ?Sized + TypeName::LowerType<'ctx>>(
+ pub fn upcast<'a, Trait: ?Sized + TypeName::MemberType>(
&'a self,
- ) -> Option<&'a WithContextLt::T<'a, 'ctx, Trait>> {
+ ) -> Option<&'a TypeName::T<'a, 'ctx, Trait>> {
self.upcast_to_id(TypeNameId::of::<Trait>())
.map(|object| match object.downcast() {
Ok(object) => object,
@@ -227,9 +198,9 @@ impl<'b, 'ctx: 'b> dyn AnyTrait<'ctx> + Send + 'b {
/// as it automatically downcasts the returned [`AnyTraitObject`].
///
/// If the returned [`AnyTraitObject`] is the wrong type, then a panic happens.
- pub fn upcast_mut<'a, Trait: ?Sized + TypeName::LowerType<'ctx>>(
+ pub fn upcast_mut<'a, Trait: ?Sized + TypeName::MemberType>(
&'a mut self,
- ) -> Option<&'a mut WithContextLt::T<'a, 'ctx, Trait>> {
+ ) -> Option<&'a mut TypeName::T<'a, 'ctx, Trait>> {
self.upcast_to_id_mut(TypeNameId::of::<Trait>())
.map(|object| match object.downcast() {
Ok(object) => object,
@@ -273,7 +244,7 @@ macro_rules! any_trait {
match id {
$(id if id == $crate::any::TypeNameId::of::<$protocol>()
=> ::core::option::Option::Some($crate::any::AnyTraitObject::<'__, $lt, _>::new::<
- $crate::any::WithContextLt::T<'__, $lt, $protocol>
+ $crate::any::TypeName::T<'__, $lt, $protocol>
>(self as _)),)*
$id => {
$($fallback)*
@@ -293,7 +264,7 @@ macro_rules! any_trait {
match id {
$(id if id == $crate::any::TypeNameId::of::<$protocol>()
=> ::core::option::Option::Some($crate::any::AnyTraitObject::<'__, $lt, _>::new::<
- $crate::any::WithContextLt::T<'__, $lt, $protocol>
+ $crate::any::TypeName::T<'__, $lt, $protocol>
>(self as _)),)*
$id => {
$($fallback)*
@@ -360,10 +331,7 @@ impl<'a, 'ctx, I: Indirect<'a>> AnyTraitObject<'a, 'ctx, I> {
/// Type erase a pointer.
///
/// `T` doesn't need to be [`Sized`]. As such, a fat pointer can be passed to this function.
- pub fn new<T: ?Sized + WithContextLt::LowerType<'a, 'ctx>>(indirect: I::ForT<T>) -> Self
- where
- WithContextLt::HigherRanked<'a, 'ctx, T>: TypeName::LowerType<'ctx>,
- {
+ pub fn new<T: ?Sized + TypeName::LowerType<'a, 'ctx>>(indirect: I::ForT<T>) -> Self {
Self {
info: TypeNameId::of_lower::<T>,
indirect: RawIndirect::new(indirect),
@@ -376,12 +344,9 @@ impl<'a, 'ctx, I: Indirect<'a>> AnyTraitObject<'a, 'ctx, I> {
///
/// If the type of the stored value is different, then `self` is
/// returned as is.
- pub fn downcast<T: ?Sized + WithContextLt::LowerType<'a, 'ctx>>(
+ pub fn downcast<T: ?Sized + TypeName::LowerType<'a, 'ctx>>(
self,
- ) -> Result<I::ForT<T>, Self>
- where
- WithContextLt::HigherRanked<'a, 'ctx, T>: TypeName::LowerType<'ctx>,
- {
+ ) -> Result<I::ForT<T>, Self> {
if self.id() == TypeNameId::of_lower::<T>() {
// SAFETY: We know that the type name type is unique per T because it is bijective.
// A self is only made in Self::new where the info is taken from T.
@@ -405,8 +370,6 @@ impl<'a, 'ctx, I: Indirect<'a>> AnyTraitObject<'a, 'ctx, I> {
#[cfg(test)]
mod test {
- use crate::bijective_higher_ranked_type;
-
use super::*;
#[test]
@@ -415,12 +378,16 @@ mod test {
fn get(&self) -> i32;
}
- bijective_higher_ranked_type! {
- type DynZ['ctx][]: WithContextLt['ctx][] for<'a> (dyn Z<'ctx> + 'a)
- }
+ struct DynZ;
- bijective_higher_ranked_type! {
- type [][]: TypeName[][] for<'ctx> (DynZ<'ctx>)
+ higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx] type T['a, 'ctx] for DynZ =
+ dyn Z<'ctx> + 'a;
+
+ impl['a, 'ctx] type HigherRanked['a, 'ctx] for dyn Z<'ctx> + 'a =
+ DynZ;
+ }
}
struct X<'ctx>(&'ctx i32);
@@ -433,14 +400,14 @@ mod test {
any_trait! {
impl['ctx] X<'ctx> = [
- DynZ<'ctx>
+ DynZ
]
}
let z = 42;
let x = X(&z);
let y = (&x as &(dyn AnyTrait<'_> + Send))
- .upcast::<DynZ<'_>>()
+ .upcast::<DynZ>()
.unwrap();
assert_eq!(y.get(), 42);
}
@@ -461,17 +428,13 @@ mod test {
// This proves that the bijective type names are really bijective.
fn _is_bijective_raise<'a, 'ctx: 'a, T>(
- x: &WithContextLt::T<
+ x: &TypeName::T<
'a,
'ctx,
- TypeName::T<
- 'ctx,
- TypeName::HigherRanked<'ctx, WithContextLt::HigherRanked<'a, 'ctx, T>>,
- >,
+ TypeName::HigherRanked<'a, 'ctx, T>,
>,
) where
- T: WithContextLt::LowerType<'a, 'ctx>,
- WithContextLt::HigherRanked<'a, 'ctx, T>: TypeName::LowerType<'ctx>,
+ T: TypeName::LowerType<'a, 'ctx>,
{
// If C -> B -> A -> B -> C (shown by this assignment), then C and A must be bijective.
let _y: &T = x;
@@ -480,8 +443,9 @@ mod test {
// This proves that the bijective type names are really bijective.
fn _is_bijective_lower<'a, 'ctx: 'a, U>(
x: &TypeName::HigherRanked<
+ 'a,
'ctx,
- WithContextLt::HigherRanked<'a, 'ctx, WithContextLt::T<'a, 'ctx, TypeName::T<'ctx, U>>>,
+ TypeName::T<'a, 'ctx, U>,
>,
) where
U: TypeName::MemberType,
diff --git a/src/any/static_wrapper.rs b/src/any/static_wrapper.rs
index d8c22db..58d101b 100644
--- a/src/any/static_wrapper.rs
+++ b/src/any/static_wrapper.rs
@@ -1,5 +1,7 @@
//! Wrapper types that impl [`TypeName`] when their generic type `T` is `'static`.
+use crate::{higher_ranked_type, hkt::Marker};
+
use super::*;
/// Owned static `T`.
@@ -7,21 +9,15 @@ use super::*;
#[repr(transparent)]
pub struct OwnedStatic<T: ?Sized>(pub T);
-bijective_higher_ranked_type! {
- for['ctx] use OwnedStatic[][T]: WithContextLt['ctx][]
- for<'a>
- (OwnedStatic<T>)
- where {
- T: ?Sized + 'ctx,
- }
-}
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for OwnedStatic<T> = OwnedStatic<T> where {
+ T: ?Sized + 'static
+ };
-bijective_higher_ranked_type! {
- use OwnedStatic[][T][]: TypeName[][]
- for<'ctx>
- (OwnedStatic<T>)
- where {
- T: ?Sized + 'static
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for OwnedStatic<T> = OwnedStatic<T> where {
+ T: ?Sized + 'static
+ };
}
}
@@ -29,21 +25,17 @@ bijective_higher_ranked_type! {
#[repr(transparent)]
pub struct BorrowedStatic<'ctx, T: ?Sized>(pub &'ctx T);
-bijective_higher_ranked_type! {
- use BorrowedStatic['ctx][T]: WithContextLt['ctx][]
- for<'a>
- (BorrowedStatic<'ctx, T>)
- where {
- T: ?Sized + 'ctx,
- }
-}
+pub struct BorrowedStaticHrt<T: ?Sized>(Marker<T>);
-bijective_higher_ranked_type! {
- pub type [][T][]: TypeName[][]
- for<'ctx>
- (BorrowedStatic<'ctx, T>)
- where {
- T: ?Sized + 'static
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for BorrowedStaticHrt<T> = BorrowedStatic<'ctx, T> where {
+ T: ?Sized + 'static
+ };
+
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for BorrowedStatic<'ctx, T> = BorrowedStaticHrt<T> where {
+ T: ?Sized + 'static
+ };
}
}
@@ -51,21 +43,17 @@ bijective_higher_ranked_type! {
#[repr(transparent)]
pub struct TempBorrowedStatic<'a, T: ?Sized>(pub &'a T);
-bijective_higher_ranked_type! {
- use TempBorrowedStatic['ctx][T]: WithContextLt['ctx][]
- for<'a>
- (TempBorrowedStatic<'a, T>)
- where {
- T: ?Sized + 'ctx,
- }
-}
+pub struct TempBorrowedStaticHrt<T: ?Sized>(Marker<T>);
-bijective_higher_ranked_type! {
- pub type [][T]: TypeName[][]
- for<'ctx>
- (TempBorrowedStatic<'ctx, T>)
- where {
- T: ?Sized + 'static
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for TempBorrowedStaticHrt<T> = TempBorrowedStatic<'a, T> where {
+ T: ?Sized + 'static
+ };
+
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for TempBorrowedStatic<'a, T> = TempBorrowedStaticHrt<T> where {
+ T: ?Sized + 'static
+ };
}
}
@@ -73,21 +61,17 @@ bijective_higher_ranked_type! {
#[repr(transparent)]
pub struct BorrowedMutStatic<'ctx, T: ?Sized>(pub &'ctx mut T);
-bijective_higher_ranked_type! {
- use BorrowedMutStatic['ctx][T]: WithContextLt['ctx][]
- for<'a>
- (BorrowedMutStatic<'ctx, T>)
- where {
- T: ?Sized + 'ctx,
- }
-}
+pub struct BorrowedMutStaticHrt<T: ?Sized>(Marker<T>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for BorrowedMutStaticHrt<T> = BorrowedMutStatic<'ctx, T> where {
+ T: ?Sized + 'static
+ };
-bijective_higher_ranked_type! {
- pub type [][T][]: TypeName[][]
- for<'ctx>
- (BorrowedMutStatic<'ctx, T>)
- where {
- T: ?Sized + 'static
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for BorrowedMutStatic<'ctx, T> = BorrowedMutStaticHrt<T> where {
+ T: ?Sized + 'static
+ };
}
}
@@ -95,21 +79,17 @@ bijective_higher_ranked_type! {
#[repr(transparent)]
pub struct TempBorrowedMutStatic<'a, T: ?Sized>(pub &'a mut T);
-bijective_higher_ranked_type! {
- use TempBorrowedMutStatic['ctx][T]: WithContextLt['ctx][]
- for<'a>
- (TempBorrowedMutStatic<'a, T>)
- where {
- T: ?Sized + 'ctx,
- }
-}
+pub struct TempBorrowedMutStaticHrt<T: ?Sized>(Marker<T>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for TempBorrowedMutStaticHrt<T> = TempBorrowedMutStatic<'a, T> where {
+ T: ?Sized + 'static
+ };
-bijective_higher_ranked_type! {
- pub type[][T][]: TypeName[][]
- for<'ctx>
- (TempBorrowedMutStatic<'ctx, T>)
- where {
- T: ?Sized + 'static
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for TempBorrowedMutStatic<'a, T> = TempBorrowedMutStaticHrt<T> where {
+ T: ?Sized + 'static
+ };
}
}
@@ -119,22 +99,15 @@ bijective_higher_ranked_type! {
pub struct BoxedStatic<T: ?Sized>(pub Box<T>);
#[cfg(feature = "alloc")]
-bijective_higher_ranked_type! {
- for['ctx] use BoxedStatic[][T]: WithContextLt['ctx][]
- for<'a>
- (BoxedStatic<T>)
- where {
- T: ?Sized + 'ctx,
- }
-}
-
-#[cfg(feature = "alloc")]
-bijective_higher_ranked_type! {
- use BoxedStatic [][T][]: TypeName[][]
- for<'ctx>
- (BoxedStatic<T>)
- where {
- T: ?Sized + 'static
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for BoxedStatic<T> = BoxedStatic<T> where {
+ T: ?Sized + 'static
+ };
+
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for BoxedStatic<T> = BoxedStatic<T> where {
+ T: ?Sized + 'static
+ };
}
}
diff --git a/src/any/type_name_id.rs b/src/any/type_name_id.rs
index 1b173f8..5776063 100644
--- a/src/any/type_name_id.rs
+++ b/src/any/type_name_id.rs
@@ -3,7 +3,7 @@ use core::any::TypeId;
#[cfg(feature = "better_errors")]
use core::any::type_name;
-use super::{TypeName, WithContextLt};
+use super::TypeName;
/// [`TypeId`] for the [`TypeName`] family of types.
///
@@ -20,34 +20,21 @@ pub struct TypeNameId {
}
impl TypeNameId {
- /// Get the type ID from a [`TypeName`] higher ranked type.
- pub fn of_type_name<T: ?Sized + TypeName::MemberType>() -> Self {
- Self {
- name_id: TypeId::of::<T>(),
-
- #[cfg(feature = "better_errors")]
- name: type_name::<WithContextLt::T<'_, '_, TypeName::T<'_, T>>>(),
- }
- }
-
/// Get the type ID from a [`TypeName::LowerType`] ([`WithContextLt`]) higher ranked type.
- pub fn of<'ctx, T: ?Sized + TypeName::LowerType<'ctx>>() -> Self {
+ pub fn of<T: ?Sized + TypeName::MemberType>() -> Self {
Self {
- name_id: TypeId::of::<TypeName::HigherRanked<'ctx, T>>(),
+ name_id: TypeId::of::<T>(),
#[cfg(feature = "better_errors")]
- name: type_name::<WithContextLt::T<'_, '_, T>>(),
+ name: type_name::<TypeName::T<'_, '_, T>>(),
}
}
/// Get the type ID from a lower type.
- pub fn of_lower<'a, 'ctx: 'a, T: ?Sized + WithContextLt::LowerType<'a, 'ctx>>() -> Self
- where
- WithContextLt::HigherRanked<'a, 'ctx, T>: TypeName::LowerType<'ctx>,
- {
+ pub fn of_lower<'a, 'ctx: 'a, T: ?Sized + TypeName::LowerType<'a, 'ctx>>() -> Self {
Self {
name_id: TypeId::of::<
- TypeName::HigherRanked<'ctx, WithContextLt::HigherRanked<'a, 'ctx, T>>,
+ TypeName::HigherRanked<'a, 'ctx, T>,
>(),
#[cfg(feature = "better_errors")]
@@ -56,10 +43,7 @@ impl TypeNameId {
}
/// Get the type ID of a lower type's value.
- pub fn of_value<'a, 'ctx: 'a, T: ?Sized + WithContextLt::LowerType<'a, 'ctx>>(_: &T) -> Self
- where
- WithContextLt::HigherRanked<'a, 'ctx, T>: TypeName::LowerType<'ctx>,
- {
+ pub fn of_value<'a, 'ctx: 'a, T: ?Sized + TypeName::LowerType<'a, 'ctx>>(_: &T) -> Self {
Self::of_lower::<'a, 'ctx, T>()
}
}
@@ -106,28 +90,28 @@ impl core::hash::Hash for TypeNameId {
#[cfg(test)]
mod test {
- use crate::bijective_higher_ranked_type;
+ use crate::higher_ranked_type;
use super::*;
#[allow(unused)]
struct Example<'a, 'ctx: 'a, T>(&'a &'ctx T);
- bijective_higher_ranked_type! {
- type DynExample['ctx][T]: WithContextLt['ctx][]
- for<'a>
- (Example<'a, 'ctx, T>)
- where {
- T: 'ctx
- }
- }
-
- bijective_higher_ranked_type! {
- type NameExample[][T][]: TypeName[][]
- for<'ctx>
- (DynExample<'ctx, T>)
- where {
- T: 'static
+ struct ExampleHrt<T>(T);
+
+ higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, T] type T['a, 'ctx] for ExampleHrt<T> =
+ Example<'a, 'ctx, T>
+ where {
+ T: 'static
+ };
+
+ impl['a, 'ctx, T] type HigherRanked['a, 'ctx] for Example<'a, 'ctx, T> =
+ ExampleHrt<T>
+ where {
+ T: 'static
+ };
}
}
@@ -135,21 +119,17 @@ mod test {
fn type_name_id_is_the_same() {
let a = TypeNameId::of_value(&Example(&&()));
let b = TypeNameId::of_lower::<Example<'_, '_, ()>>();
- let c = TypeNameId::of::<DynExample<'_, ()>>();
- let d = TypeNameId::of_type_name::<NameExample<()>>();
+ let c = TypeNameId::of::<ExampleHrt<()>>();
assert_eq!(a, b);
assert_eq!(a, c);
- assert_eq!(a, d);
assert_eq!(b, c);
- assert_eq!(b, d);
- assert_eq!(c, d);
}
#[test]
fn type_name_id_is_different() {
- let a = TypeNameId::of::<DynExample<'_, i8>>();
- let b = TypeNameId::of::<DynExample<'_, u8>>();
+ let a = TypeNameId::of_lower::<Example<'_, '_, i8>>();
+ let b = TypeNameId::of_lower::<Example<'_, '_, u8>>();
assert_ne!(a, b);
}
diff --git a/src/build/builders/core/bool.rs b/src/build/builders/core/bool.rs
index b48b731..f122e8a 100644
--- a/src/build/builders/core/bool.rs
+++ b/src/build/builders/core/bool.rs
@@ -5,7 +5,7 @@ use crate::{
any_trait,
effect::{Effect, Future},
protocol::{
- visitor::{DynValue, Value, VisitResult},
+ visitor::{Value, ValueProto, VisitResult},
Visitor,
},
Flow,
@@ -61,7 +61,7 @@ impl<'ctx, E: Effect> crate::Builder<'ctx, E> for Builder<E> {
any_trait! {
impl['ctx, E] Builder<E> = [
- DynValue<'ctx, OwnedStatic<bool>, E>,
+ ValueProto<OwnedStatic<bool>, E>,
] where E: Effect
}
diff --git a/src/build/builders/debug.rs b/src/build/builders/debug.rs
index 17749dc..f1d8d1f 100644
--- a/src/build/builders/debug.rs
+++ b/src/build/builders/debug.rs
@@ -4,12 +4,11 @@ use crate::{
any::OwnedStatic,
any_trait,
effect::{Effect, Future},
- protocol::Walker,
+ protocol::{visitor::SequenceProto, Walker},
protocol::{
self,
visitor::{
- DynRequestHint, DynSequence, DynSequenceScope, DynTag, DynValue, RequestHint, Sequence,
- Tag, TagDyn, Value, VisitResult,
+ DynSequenceScope, RequestHint, RequestHintProto, Sequence, Tag, TagDyn, TagProto, Value, ValueProto, VisitResult
},
},
DynWalker, Flow,
@@ -19,15 +18,15 @@ pub struct Visitor<E>(usize, PhantomData<fn() -> E>);
any_trait! {
impl['ctx, E] Visitor<E> = [
- DynRequestHint<'ctx, E>,
+ RequestHintProto<E>,
// DynRecoverable<'a, 'ctx, E>,
- DynTag<'ctx, TagDyn, E>,
- DynValue<'ctx, OwnedStatic<&'static str>, E>,
- DynValue<'ctx, OwnedStatic<TypeId>, E>,
- DynValue<'ctx, OwnedStatic<usize>, E>,
- DynValue<'ctx, OwnedStatic<bool>, E>,
+ TagProto<TagDyn, E>,
+ ValueProto<OwnedStatic<&'static str>, E>,
+ ValueProto<OwnedStatic<TypeId>, E>,
+ ValueProto<OwnedStatic<usize>, E>,
+ ValueProto<OwnedStatic<bool>, E>,
// DynValue<'a, 'ctx, OwnedStatic<&'static [&'static str]>, E>,
- DynSequence<'ctx, E>,
+ SequenceProto<E>,
] else {
let id;
println!("Unknown trait: {:?}", id);
diff --git a/src/effect.rs b/src/effect.rs
index b50b37a..9c72977 100644
--- a/src/effect.rs
+++ b/src/effect.rs
@@ -5,12 +5,19 @@ use core::{
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
};
-use crate::{bijective_higher_ranked_trait, bijective_higher_ranked_type};
-
-bijective_higher_ranked_trait! {
- pub type class SendFuture[][Output]: [for<'lt> core::future::Future<Output = Output> + Sized + Send + 'lt]
- where {
- Output: Send,
+use crate::{higher_ranked_trait, higher_ranked_type, hkt::Marker};
+
+higher_ranked_trait! {
+ pub type class SendFuture[Output] for<'a> {
+ type Bound = &'a Output;
+
+ type T: { core::future::Future<Output = Output> + Sized + Send + 'a }
+ where {
+ Output: 'a
+ };
+ type HigherRanked: {} where {
+ // Output: Send
+ };
}
}
@@ -18,17 +25,17 @@ bijective_higher_ranked_trait! {
pub trait Effect: Send + 'static {
type Future<T: Send>: SendFuture::MemberType<T>;
- fn wrap<'a, F>(future: F) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output>
+ fn wrap<'a, F>(future: F) -> SendFuture::T<'a, F::Output, Self::Future<F::Output>>
where
F: core::future::Future + Send + 'a,
<F as core::future::Future>::Output: Send;
- fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, Self::Future<T>, T>;
+ fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, T, Self::Future<T>>;
fn map<'a, T, U, F>(
- future: SendFuture::T<'a, Self::Future<T>, T>,
+ future: SendFuture::T<'a, T, Self::Future<T>>,
func: F,
- ) -> SendFuture::T<'a, Self::Future<U>, U>
+ ) -> SendFuture::T<'a, U, Self::Future<U>>
where
T: Send,
U: Send,
@@ -38,7 +45,7 @@ pub trait Effect: Send + 'static {
#[inline]
fn wrap_boxed<'a, F>(
future: core::pin::Pin<Box<F>>,
- ) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output>
+ ) -> SendFuture::T<'a, F::Output, Self::Future<F::Output>>
where
F: core::future::Future + Send + 'a,
<F as core::future::Future>::Output: Send,
@@ -47,7 +54,7 @@ pub trait Effect: Send + 'static {
}
}
-pub type Future<'a, T, E> = SendFuture::T<'a, <E as Effect>::Future<T>, T>;
+pub type Future<'a, T, E> = SendFuture::T<'a, T, <E as Effect>::Future<T>>;
pub struct Blocking<B = Spin> {
_marker: PhantomData<fn() -> B>,
@@ -99,18 +106,26 @@ pub fn noop() -> Waker {
unsafe { Waker::from_raw(RAW) }
}
-bijective_higher_ranked_type! {
- pub type ReadyFuture[][Output]: SendFuture[][Output]
- for<'lt> (core::future::Ready<Output>)
- where {
- Output: Send,
+higher_ranked_type! {
+ impl SendFuture {
+ impl['a, Output] type T['a, Output] for core::future::Ready<Output> =
+ core::future::Ready<Output>
+ where {
+ Output: Send
+ };
+
+ impl['a, Output] type HigherRanked['a, Output] for core::future::Ready<Output> =
+ core::future::Ready<Output>
+ where {
+ Output: Send
+ };
}
}
impl<B: BlockOn> Effect for Blocking<B> {
- type Future<T: Send> = ReadyFuture<T>;
+ type Future<T: Send> = core::future::Ready<T>;
- fn wrap<'a, F>(future: F) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output>
+ fn wrap<'a, F>(future: F) -> SendFuture::T<'a, F::Output, Self::Future<F::Output>>
where
F: core::future::Future + Send + 'a,
<F as core::future::Future>::Output: Send,
@@ -118,14 +133,14 @@ impl<B: BlockOn> Effect for Blocking<B> {
core::future::ready(B::block_on(future))
}
- fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, Self::Future<T>, T> {
+ fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, T, Self::Future<T>> {
core::future::ready(value)
}
fn map<'a, T, U, F>(
- future: SendFuture::T<'a, Self::Future<T>, T>,
+ future: SendFuture::T<'a, T, Self::Future<T>>,
func: F,
- ) -> SendFuture::T<'a, Self::Future<U>, U>
+ ) -> SendFuture::T<'a, U, Self::Future<U>>
where
T: Send,
U: Send,
@@ -158,11 +173,22 @@ mod sealed {
}
#[cfg(feature = "alloc")]
-bijective_higher_ranked_type! {
- pub type BoxFuture[][Output]: SendFuture[][Output]
- for<'lt> (sealed::BoxedFuture<'lt, Output>)
- where {
- Output: Send,
+pub struct BoxedFutureHrt<Output>(Marker<Output>);
+
+#[cfg(feature = "alloc")]
+higher_ranked_type! {
+ impl SendFuture {
+ impl['a, Output] type T['a, Output] for BoxedFutureHrt<Output> =
+ sealed::BoxedFuture<'a, Output>
+ where {
+ Output: Send
+ };
+
+ impl['a, Output] type HigherRanked['a, Output] for sealed::BoxedFuture<'a, Output> =
+ BoxedFutureHrt<Output>
+ where {
+ Output: Send
+ };
}
}
@@ -171,9 +197,9 @@ pub enum Async {}
#[cfg(feature = "alloc")]
impl Effect for Async {
- type Future<T: Send> = BoxFuture<T>;
+ type Future<T: Send> = BoxedFutureHrt<T>;
- fn wrap<'a, F>(future: F) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output>
+ fn wrap<'a, F>(future: F) -> SendFuture::T<'a, F::Output, Self::Future<F::Output>>
where
F: core::future::Future + Send + 'a,
<F as core::future::Future>::Output: Send,
@@ -181,14 +207,14 @@ impl Effect for Async {
sealed::BoxedFuture::Box(Box::pin(future))
}
- fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, Self::Future<T>, T> {
+ fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, T, Self::Future<T>> {
sealed::BoxedFuture::Ready(core::future::ready(value))
}
fn map<'a, T, U, F>(
- future: SendFuture::T<'a, Self::Future<T>, T>,
+ future: SendFuture::T<'a, T, Self::Future<T>>,
func: F,
- ) -> SendFuture::T<'a, Self::Future<U>, U>
+ ) -> SendFuture::T<'a, U, Self::Future<U>>
where
T: Send,
U: Send,
@@ -205,7 +231,7 @@ impl Effect for Async {
fn wrap_boxed<'a, F>(
future: core::pin::Pin<Box<F>>,
- ) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output>
+ ) -> SendFuture::T<'a, F::Output, Self::Future<F::Output>>
where
F: core::future::Future + Send + 'a,
<F as core::future::Future>::Output: Send,
diff --git a/src/hkt.rs b/src/hkt.rs
index 8cc3952..55e9856 100644
--- a/src/hkt.rs
+++ b/src/hkt.rs
@@ -19,12 +19,14 @@
//! Bounding a generic by a higher-ranked trait simultaniously allows any higher-ranked type with
//! a "true" type with the required traits and any lifetime to be given to that "true" type.
+use core::marker::PhantomData;
+
#[derive(Debug, Default, Copy, Clone)]
#[repr(transparent)]
pub struct Invariant<'a>(PhantomData<fn(&'a ()) -> &'a ()>);
#[repr(transparent)]
-pub struct Marker<T>(PhantomData<fn() -> T>);
+pub struct Marker<T: ?Sized>(PhantomData<fn() -> *const T>);
impl<T> Copy for Marker<T> {}
impl<T> Clone for Marker<T> {
@@ -47,412 +49,100 @@ impl<T> Default for Marker<T> {
#[doc(hidden)]
#[macro_export]
-macro_rules! bijective_higher_ranked_trait {
+macro_rules! higher_ranked_trait {
{
- $(#[$($meta:tt)*])*
- $vis:vis type class $name:ident[
- $($lifetimes:lifetime),*
- ][
- $($generic:ident),*
- ]: $({$($self_provides:tt)*})? [for<$lt:lifetime> $($($provides:tt)+)?]
- $(where {
- $($bound:tt)*
- })?
- $(for where {
- $($for_bound:tt)*
- })?
+ $vis:vis type class $name:ident$([$($generic:tt)*])? for<$($lt:lifetime),+> {
+ type Bound = $bound:ty;
+
+ type T: {$($lower:tt)*} $(where {$($lower_where:tt)*})?;
+
+ type HigherRanked: {$($higher:tt)*} $(where {$($higher_where:tt)*})?;
+ }
} => {
- $(#[$($meta)*])*
$vis mod $name {
- #![allow(unused, non_snake_case)]
-
- use super::*;
+ #![allow(non_snake_case)]
- /// Trait for lowering a higher ranked type to a lower type.
- ///
- /// Do not use this trait directly instead use the [`MemberType`] trait and [`T`]
- /// type alias.
- ///
- /// This acts to inject a lifetime into the higher ranked type to make it concrete.
- pub trait LowerForLt<
- $lt,
- $($lifetimes: $lt,)*
- B: $lt,
- $($generic: $lt),*
- >
- $(: $($self_provides)*)?
+ pub trait LowerForLt<$($lt,)+ $($($generic)*,)? B>
where
- $($($bound)*)?
- $($($for_bound)*)?
+ $($($lower_where)*)?
+ $($($higher_where)*)?
{
- /// The lower type for this higher ranked type.
- ///
- /// The lower type must live for a minimum of the injected lifetime.
- ///
- /// Note this type must be raisable back to the same higher ranked type to make
- /// this a bijective mapping.
- type T: ?Sized + RaiseForLt<
- $lt,
- $($lifetimes,)*
- &$lt ($(&$lifetimes (),)* $(*const $generic,)*),
- $($generic,)*
- HigherRanked = Self
- > $(+ $($provides)+)? + $lt;
+ type T: RaiseForLt<$($lt,)+ $($($generic)*,)? B, HigherRanked = Self> + ?Sized + $($lower)*;
}
- /// Trait for raising a lower type to it's higher ranked form.
- ///
- /// Do not use this trait directly instead use the [`LowerType`] trait and [`HigherRanked`]
- /// type alias.
- ///
- /// this acts to remove a lifetime from the lower type.
- pub trait RaiseForLt<$lt, $($lifetimes: $lt,)* B: $lt, $($generic: $lt),*>
+ pub trait RaiseForLt<$($lt,)+ $($($generic)*,)? B>
where
- $($($bound)*)?
- $($($for_bound)*)?
+ $($($lower_where)*)?
+ $($($higher_where)*)?
{
- /// The higher ranked type for this lower type.
- ///
- /// Note this type must be lowerable back to the same lower type to make
- /// this a bijective mapping.
- type HigherRanked: ?Sized + LowerForLt<
- $lt,
- $($lifetimes,)*
- &$lt ($(&$lifetimes (),)* $(*const $generic,)*),
- $($generic,)*
- T = Self
- > $(+ $lifetimes)*;
+ type HigherRanked: LowerForLt<$($lt,)+ $($($generic)*,)? B, T = Self> + ?Sized + $($higher)*;
}
- /// Trait for higher ranked types of this form.
- ///
- /// A higher ranked type can have a lifetime injected to form a lower type.
- /// To perform this operation use the [`T`] type alias.
- ///
- /// This is basically a trait alias for the bound `for<'a> LowerForLt<'a, ...>`.
- pub trait MemberType<$($lifetimes,)* $($generic),*>:
- for<$lt> LowerForLt<
- $lt,
- $($lifetimes,)*
- // Use a implied bound to make sure the lifetime from the for syntax is
- // correctly bounded.
- &$lt ($(&$lifetimes (),)* $(*const $generic,)*),
- $($generic),*
- >
- where
- $($($bound)*)?
+ pub type Bound<$($lt,)+ $($($generic)*)?> = $bound;
+
+ pub trait MemberType$(<$($generic)*>)?:
+ for<$($lt,)+> LowerForLt<$($lt,)+ $($($generic)*,)? Bound<$($lt,)+ $($($generic)*)?>> + $($higher)*
+ $(where $($higher_where)*)?
{}
- // Impl the higher ranked trait for all higher ranked types with the ability to lower.
- impl<
- $($lifetimes,)*
- __: ?Sized,
- $($generic),*
- > MemberType<$($lifetimes,)* $($generic),*> for __
+ impl<$($($generic)*,)? __: ?Sized> MemberType$(<$($generic)*>)? for __
where
- __: for<$lt> LowerForLt<
- $lt,
- $($lifetimes,)*
- &$lt ($(&$lifetimes (),)* $(*const $generic,)*),
- $($generic),*
- >,
- $($($bound)*)?
+ __: for<$($lt,)+> LowerForLt<$($lt,)+ $($($generic)*,)? Bound<$($lt,)+ $($($generic)*)?>> + $($higher)?
+ $($($higher_where)*)?
{}
- /// Inject a lifetime into a higher ranked type to form its lower type.
- pub type T<$lt, $($lifetimes,)* __, $($generic),*> =
- <__ as LowerForLt<
- $lt,
- $($lifetimes,)*
- &$lt ($(&$lifetimes (),)* $(*const $generic,)*),
- $($generic),*
- >>::T;
-
- /// Trait for lower types with a higher ranked form.
- ///
- /// A lower type can have a lifetime removed to form a higher ranked type.
- /// To perform this operation use the [`HigherRanked`] type alias.
- ///
- /// This is basically a trait alias for the bound `RaiseForLt<'a, ...>`.
- pub trait LowerType<
- $lt,
- $($lifetimes: $lt,)*
- $($generic: $lt),*
- >: RaiseForLt<
- $lt,
- $($lifetimes,)*
- &$lt ($(&$lifetimes (),)* $(*const $generic,)*),
- $($generic),*
- > $(+ $($provides)+)?
+ pub trait LowerType<$($lt,)+ $($($generic)*)?>:
+ RaiseForLt<$($lt,)+ $($($generic)*,)? Bound<$($lt,)+ $($($generic)*)?>> + $($lower)*
where
- $($($bound)*)?
+ $($($lower_where)*)?
+ $($($higher_where)*)?
{}
- // Impl the lower type trait for all lower types with the ability to raise.
- impl<
- $lt,
- $($lifetimes: $lt,)*
- __: ?Sized,
- $($generic: $lt),*
- > LowerType<$lt, $($lifetimes,)* $($generic),*> for __
+ impl<$($lt,)+ $($($generic)*,)? __: ?Sized> LowerType<$($lt,)+ $($($generic)*)?> for __
where
- __: RaiseForLt<
- $lt,
- $($lifetimes,)*
- &$lt ($(&$lifetimes (),)* $(*const $generic,)*),
- $($generic),*
- > $(+ $($provides)+)?,
- $($($bound)*)?
+ __: RaiseForLt<$($lt,)+ $($($generic)*,)? Bound<$($lt,)+ $($($generic)*)?>> + $($lower)*,
+ $($($lower_where)*)?
+ $($($higher_where)*)?
{}
- /// Remove a lifetime into a lower type to form its higher ranked type.
- pub type HigherRanked<$lt, $($lifetimes,)* __, $($generic),*> =
- <__ as RaiseForLt<
- $lt,
- $($lifetimes,)*
- &$lt ($(&$lifetimes (),)* $(*const $generic,)*),
- $($generic),*
- >>::HigherRanked;
+ pub type T<$($lt,)+ $($($generic)*,)? __> =
+ <__ as LowerForLt<$($lt,)+ $($($generic)*,)? Bound<$($lt,)+ $($($generic)*)?>>>::T;
+
+ pub type HigherRanked<$($lt,)+ $($($generic)*,)? __> =
+ <__ as RaiseForLt<$($lt,)+ $($($generic)*,)? Bound<$($lt,)+ $($($generic)*)?>>>::HigherRanked;
}
- };
+ }
}
+pub use higher_ranked_trait;
-use core::marker::PhantomData;
-
-#[doc(inline)]
-pub use bijective_higher_ranked_trait;
-
-/// Generate a higher-ranked type.
#[doc(hidden)]
#[macro_export]
-macro_rules! bijective_higher_ranked_type {
+macro_rules! higher_ranked_type {
{
- $(for[$($extra_lt:lifetime)*])? use $name:ident[
- $($ctx:lifetime),*
- ][
- $($generic:ident),*
- ]$([
- $($forwarding_generic:ident[$($forward_lt:lifetime),*][$($forward_generic:ident),*]),*
- ])?: $type_class:ident[$($type_class_lifetime:lifetime)*][$($type_class_generic:ident)*]
- for<$lt:lifetime>
- ($for_lt_type:ty)
- ($higher_ranked_type:ty)
- $(where {$($bound:tt)*})?
+ impl $higher_trait:ident {
+ impl$([$($lower_generic:tt)*])? type T[$($lower_forward:tt)*] for $lower_higher:ty =
+ $lower:ty
+ $(where {$($lower_where:tt)*})?;
+
+ impl$([$($higher_generic:tt)*])? type HigherRanked[$($higher_forward:tt)*] for $higher_lower:ty =
+ $higher:ty
+ $(where {$($higher_where:tt)*})?;
+ }
} => {
- impl<
- $lt,
- $($($extra_lt,)*)?
- $($ctx,)*
- $($generic,)*
- $($($forwarding_generic),*)?
- > $type_class::LowerForLt<
- $lt,
- $($type_class_lifetime,)*
- &$lt (
- $(&$type_class_lifetime (),)*
- $(*const $type_class_generic,)*
- ),
- $($type_class_generic),*
- > for $name<
- $($ctx,)*
- $($generic,)*
- $($($forwarding_generic),*)?
- >
- where
- $($(
- $forwarding_generic: $type_class::LowerForLt<
- $lt,
- $($forward_lt,)*
- &$lt (
- $(&$forward_lt (),)*
- $(*const $forward_generic,)*
- ),
- $($forward_generic,)*
- >,
- )*)?
- $($($bound)*)?
+ impl$(<$($lower_generic)*>)* $higher_trait::LowerForLt<$($lower_forward)*, $higher_trait::Bound<$($lower_forward)*>> for $lower_higher
+ $(where $($lower_where)*)?
{
- type T = $for_lt_type;
+ type T = $lower;
}
- impl<
- $lt,
- $($($extra_lt,)*)?
- $($ctx,)*
- $($generic,)*
- $($($forwarding_generic),*)?
- > $type_class::RaiseForLt<
- $lt,
- $($type_class_lifetime,)*
- &$lt (
- $(&$type_class_lifetime (),)*
- $(*const $type_class_generic,)*
- ),
- $($type_class_generic),*
- > for $higher_ranked_type
- where
- $($(
- $forwarding_generic: $type_class::RaiseForLt<
- $lt,
- $($forward_lt,)*
- &$lt (
- $(&$forward_lt (),)*
- $(*const $forward_generic,)*
- ),
- $($forward_generic,)*
- >,
- )*)?
- $($($bound)*)?
+ impl$(<$($higher_generic)*>)* $higher_trait::RaiseForLt<$($higher_forward)*, $higher_trait::Bound<$($higher_forward)*>> for $higher_lower
+ $(where $($higher_where)*)?
{
- type HigherRanked = $name<
- $($ctx,)*
- $($generic,)*
- $($(
- <$forwarding_generic as $type_class::RaiseForLt<
- $lt,
- $($forward_lt,)*
- &$lt (
- $(&$forward_lt (),)*
- $(*const $forward_generic,)*
- ),
- $($forward_generic,)*
- >>::HigherRanked
- ),*)?
- >;
- }
- };
- {
- $(#[$($meta:tt)*])*
- $vis:vis $(for[$($extra_lt:lifetime)*])? type $name:ident[
- $($ctx:lifetime),*
- ][
- $($generic:ident),*
- ]$([
- $($forwarding_generic:ident[$($forward_lt:lifetime),*][$($forward_generic:ident),*]),*
- ])?: $type_class:ident[$($type_class_lifetime:lifetime)*][$($type_class_generic:ident)*]
- for<$lt:lifetime>
- ($for_lt_type:ty)
- ($higher_ranked_type:ty)
- $(where {$($bound:tt)*})?
- } => {
- $(#[$($meta)*])*
- $vis struct $name<
- $($ctx,)*
- $($generic: ?Sized,)*
- $($($forwarding_generic: ?Sized),*)?
- >(
- core::marker::PhantomData<fn() -> (
- $(&$ctx (),)*
- $(*const $generic,)*
- $($(*const $forwarding_generic,)*)?
- )>
- );
-
- $crate::hkt::bijective_higher_ranked_type! {
- $(for[$($extra_lt)*])? use $name[
- $($ctx),*
- ][
- $($generic),*
- ]$([
- $($forwarding_generic[$($forward_lt),*][$($forward_generic),*]),*
- ])?: $type_class[$($type_class_lifetime)*][$($type_class_generic)*]
- for<$lt>
- ($for_lt_type)
- ($higher_ranked_type)
- $(where {$($bound)*})?
- }
- };
- {
- $vis:vis $(for[$($extra_lt:lifetime)*])? type [
- $($ctx:lifetime),*
- ][
- $($generic:ident),*
- ]$([
- $($forwarding_generic:ident[$($forward_lt:lifetime),*][$($forward_generic:ident),*]),*
- ])?: $type_class:ident[$($type_class_lifetime:lifetime)*][$($type_class_generic:ident)*]
- for<$lt:lifetime>
- ($for_lt_type:ty)
- $(($higher_ranked_type:ty))?
- $(where {$($bound:tt)*})?
- } => {
- const _: () = {
- $crate::hkt::bijective_higher_ranked_type! {
- $vis $(for[$($extra_lt)*])? type __HigherRanked[
- $($ctx),*
- ][
- $($generic),*
- ]$([
- $($forwarding_generic[$($forward_lt),*][$($forward_generic),*]),*
- ])?: $type_class[$($type_class_lifetime)*][$($type_class_generic)*]
- for<$lt>
- ($for_lt_type)
- $(($higher_ranked_type))?
- $(where {$($bound)*})?
- }
- };
- };
- {
- $(#[$($meta:tt)*])*
- $vis:vis $(for[$($extra_lt:lifetime)*])? type $name:ident[
- $($ctx:lifetime),*
- ][
- $($generic:ident),*
- ]$([
- $($forwarding_generic:ident[$($forward_lt:lifetime),*][$($forward_generic:ident),*]),*
- ])?: $type_class:ident[$($type_class_lifetime:lifetime)*][$($type_class_generic:ident)*]
- for<$lt:lifetime>
- ($for_lt_type:ty)
- $(where {$($bound:tt)*})?
- } => {
- $crate::hkt::bijective_higher_ranked_type! {
- $(#[$($meta)*])*
- $vis $(for[$($extra_lt)*])? type $name[
- $($ctx),*
- ][
- $($generic),*
- ]$([
- $($forwarding_generic[$($forward_lt),*][$($forward_generic),*]),*
- ])?: $type_class[$($type_class_lifetime)*][$($type_class_generic)*]
- for<$lt>
- ($for_lt_type)
- ($for_lt_type)
- $(where {$($bound)*})?
- }
- };
- {
- $(for[$($extra_lt:lifetime)*])? use $name:ident[
- $($ctx:lifetime),*
- ][
- $($generic:ident),*
- ]$([
- $($forwarding_generic:ident[$($forward_lt:lifetime),*][$($forward_generic:ident),*]),*
- ])?: $type_class:ident[$($type_class_lifetime:lifetime)*][$($type_class_generic:ident)*]
- for<$lt:lifetime>
- ($for_lt_type:ty)
- $(where {$($bound:tt)*})?
- } => {
- $crate::hkt::bijective_higher_ranked_type! {
- $(for[$($extra_lt)*])? use $name[
- $($ctx),*
- ][
- $($generic),*
- ]$([
- $($forwarding_generic[$($forward_lt),*][$($forward_generic),*]),*
- ])?: $type_class[$($type_class_lifetime)*][$($type_class_generic)*]
- for<$lt>
- ($for_lt_type)
- ($for_lt_type)
- $(where {$($bound)*})?
+ type HigherRanked = $higher;
}
}
}
-
-#[doc(inline)]
-pub use bijective_higher_ranked_type;
-
-bijective_higher_ranked_trait! {
- pub type class AnySizedSend[][]: [for<'lt> Send + Sized]
-}
+pub use higher_ranked_type;
// #[cfg(test)]
// mod test {
diff --git a/src/lib.rs b/src/lib.rs
index 4a37b96..fe4d9da 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -145,18 +145,6 @@ macro_rules! Walk {
};
}
-pub struct Demo {
- pub a: bool,
- pub b: bool,
-}
-
-Walk! {
- pub struct Demo {
- a: bool,
- b: bool,
- }
-}
-
// #[cfg(test)]
// mod test {
// use crate::effect::{BlockOn, Blocking, Spin};
diff --git a/src/protocol/visitor/recoverable.rs b/src/protocol/visitor/recoverable.rs
index e23c69e..af3e494 100644
--- a/src/protocol/visitor/recoverable.rs
+++ b/src/protocol/visitor/recoverable.rs
@@ -1,10 +1,5 @@
use crate::{
- any::{TypeName, WithContextLt},
- bijective_higher_ranked_type,
- effect::{Effect, Future},
- hkt::AnySizedSend,
- protocol::{walker::hint::HintMeta, Visitor},
- Status,
+ any::{TypeName}, effect::{Effect, Future}, higher_ranked_type, hkt::Marker, protocol::{walker::hint::{HintKnown, HintMeta}, Visitor}, Status
};
use super::VisitResult;
@@ -16,21 +11,21 @@ pub trait Recoverable<'ctx, E: Effect> {
) -> Future<'a, VisitResult<DynRecoverableScope<'a, 'ctx, E>>, E>;
}
-bijective_higher_ranked_type! {
- pub type DynRecoverable['ctx][E]: WithContextLt['ctx][]
- for<'a>
- (dyn Recoverable<'ctx, E> + Send + 'a)
- where {
- E: Effect
- }
-}
+pub struct RecoverableProto<E: Effect>(Marker<E>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, E] type T['a, 'ctx] for RecoverableProto<E> =
+ dyn Recoverable<'ctx, E> + Send + 'a
+ where {
+ E: Effect
+ };
-bijective_higher_ranked_type! {
- pub type [][E]: TypeName[][]
- for<'ctx>
- (DynRecoverable<'ctx, E>)
- where {
- E: Effect
+ impl['a, 'ctx, E] type HigherRanked['a, 'ctx] for dyn Recoverable<'ctx, E> + Send + 'a =
+ RecoverableProto<E>
+ where {
+ E: Effect
+ };
}
}
@@ -40,12 +35,20 @@ pub trait RecoverableScope<'ctx, E: Effect> {
pub type DynRecoverableScope<'a, 'ctx, E> = &'a mut (dyn RecoverableScope<'ctx, E> + Send + 'a);
-bijective_higher_ranked_type! {
- pub type RecoverableKnownHkt[][]: AnySizedSend[][] for<'lt> (())
+pub struct RecoverableKnown;
+
+higher_ranked_type! {
+ impl HintKnown {
+ impl['a] type T['a] for RecoverableKnown =
+ RecoverableKnown;
+
+ impl['a] type HigherRanked['a] for RecoverableKnown =
+ RecoverableKnown;
+ }
}
-impl<'ctx, E: Effect> HintMeta<'ctx> for DynRecoverable<'ctx, E> {
- type Known = RecoverableKnownHkt;
+impl<'ctx, E: Effect> HintMeta<'ctx> for RecoverableProto<E> {
+ type Known = RecoverableKnown;
type Hint = ();
}
@@ -54,7 +57,7 @@ pub fn visit_recoverable<'a, 'ctx, E: Effect>(
visitor: Visitor<'a, 'ctx>,
scope: DynRecoverableScope<'a, 'ctx, E>,
) -> Future<'a, VisitResult<DynRecoverableScope<'a, 'ctx, E>>, E> {
- if let Some(object) = visitor.upcast_mut::<DynRecoverable<'ctx, E>>() {
+ if let Some(object) = visitor.upcast_mut::<RecoverableProto<E>>() {
// Allow the visitor to give a hint if it wants.
object.visit(scope)
} else {
diff --git a/src/protocol/visitor/request_hint.rs b/src/protocol/visitor/request_hint.rs
index 8b4f573..831594f 100644
--- a/src/protocol/visitor/request_hint.rs
+++ b/src/protocol/visitor/request_hint.rs
@@ -1,8 +1,5 @@
use crate::{
- any::{TypeName, WithContextLt},
- bijective_higher_ranked_type,
- effect::{Effect, Future},
- protocol::{Visitor, Walker},
+ any::{TypeName}, effect::{Effect, Future}, higher_ranked_type, hkt::Marker, protocol::{Visitor, Walker}
};
use super::VisitResult;
@@ -19,21 +16,21 @@ pub trait RequestHint<'ctx, E: Effect> {
) -> Future<'a, VisitResult<Walker<'a, 'ctx>>, E>;
}
-bijective_higher_ranked_type! {
- pub type DynRequestHint['ctx][E]: WithContextLt['ctx][]
- for<'a>
- (dyn RequestHint<'ctx, E> + Send + 'a)
- where {
- E: Effect
- }
-}
+pub struct RequestHintProto<E: Effect>(Marker<E>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, E] type T['a, 'ctx] for RequestHintProto<E> =
+ dyn RequestHint<'ctx, E> + Send + 'a
+ where {
+ E: Effect
+ };
-bijective_higher_ranked_type! {
- pub type [][E]: TypeName[][]
- for<'ctx>
- (DynRequestHint<'ctx, E>)
- where {
- E: Effect
+ impl['a, 'ctx, E] type HigherRanked['a, 'ctx] for dyn RequestHint<'ctx, E> + Send + 'a =
+ RequestHintProto<E>
+ where {
+ E: Effect
+ };
}
}
@@ -48,7 +45,7 @@ pub fn visit_request_hint<'a, 'ctx, E: Effect>(
visitor: Visitor<'a, 'ctx>,
walker: Walker<'a, 'ctx>,
) -> Future<'a, VisitResult<Walker<'a, 'ctx>>, E> {
- if let Some(object) = visitor.upcast_mut::<DynRequestHint<'ctx, E>>() {
+ if let Some(object) = visitor.upcast_mut::<RequestHintProto<E>>() {
// Allow the visitor to give a hint if it wants.
object.request_hint(walker)
} else {
diff --git a/src/protocol/visitor/sequence.rs b/src/protocol/visitor/sequence.rs
index 23bc3ce..32deb9c 100644
--- a/src/protocol/visitor/sequence.rs
+++ b/src/protocol/visitor/sequence.rs
@@ -1,10 +1,5 @@
use crate::{
- any::{TypeName, WithContextLt},
- bijective_higher_ranked_type,
- effect::{Effect, Future},
- hkt::AnySizedSend,
- protocol::{walker::hint::HintMeta, Visitor},
- Flow,
+ any::{TypeName}, effect::{Effect, Future}, higher_ranked_type, hkt::Marker, protocol::{walker::hint::{HintKnown, HintMeta}, Visitor}, Flow
};
use super::VisitResult;
@@ -16,21 +11,21 @@ pub trait Sequence<'ctx, E: Effect> {
) -> Future<'a, VisitResult<DynSequenceScope<'a, 'ctx, E>>, E>;
}
-bijective_higher_ranked_type! {
- pub type DynSequence['ctx][E]: WithContextLt['ctx][]
- for<'a>
- (dyn Sequence<'ctx, E> + Send + 'a)
- where {
- E: Effect
- }
-}
+pub struct SequenceProto<E: Effect>(Marker<E>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, E] type T['a, 'ctx] for SequenceProto<E> =
+ dyn Sequence<'ctx, E> + Send + 'a
+ where {
+ E: Effect
+ };
-bijective_higher_ranked_type! {
- pub type [][E]: TypeName[][]
- for<'ctx>
- (DynSequence<'ctx, E>)
- where {
- E: Effect
+ impl['a, 'ctx, E] type HigherRanked['a, 'ctx] for dyn Sequence<'ctx, E> + Send + 'a =
+ SequenceProto<E>
+ where {
+ E: Effect
+ };
}
}
@@ -42,8 +37,14 @@ pub trait SequenceScope<'ctx, E: Effect> {
pub type DynSequenceScope<'a, 'ctx, E> = &'a mut (dyn SequenceScope<'ctx, E> + Send + 'a);
-bijective_higher_ranked_type! {
- pub type SequenceKnownHkt[][]: AnySizedSend[][] for<'lt> (SequenceKnown)
+higher_ranked_type! {
+ impl HintKnown {
+ impl['a] type T['a] for SequenceKnown =
+ SequenceKnown;
+
+ impl['a] type HigherRanked['a] for SequenceKnown =
+ SequenceKnown;
+ }
}
#[derive(Default)]
@@ -55,8 +56,8 @@ pub struct SequenceHint {
pub len: (usize, Option<usize>),
}
-impl<'ctx, E: Effect> HintMeta<'ctx> for DynSequence<'ctx, E> {
- type Known = SequenceKnownHkt;
+impl<'ctx, E: Effect> HintMeta<'ctx> for SequenceProto<E> {
+ type Known = SequenceKnown;
type Hint = SequenceHint;
}
@@ -65,7 +66,7 @@ pub fn visit_sequence<'a, 'ctx, E: Effect>(
visitor: Visitor<'a, 'ctx>,
scope: DynSequenceScope<'a, 'ctx, E>,
) -> Future<'a, VisitResult<DynSequenceScope<'a, 'ctx, E>>, E> {
- if let Some(object) = visitor.upcast_mut::<DynSequence<'ctx, E>>() {
+ if let Some(object) = visitor.upcast_mut::<SequenceProto<E>>() {
// Allow the visitor to give a hint if it wants.
object.visit(scope)
} else {
diff --git a/src/protocol/visitor/tag.rs b/src/protocol/visitor/tag.rs
index d6cf1ae..1cfb29e 100644
--- a/src/protocol/visitor/tag.rs
+++ b/src/protocol/visitor/tag.rs
@@ -1,11 +1,5 @@
use crate::{
- any::{TypeName, WithContextLt},
- bijective_higher_ranked_type,
- effect::{Effect, Future},
- hkt::AnySizedSend,
- protocol::{walker::hint::HintMeta, Visitor},
- symbol::Symbol,
- DynWalker, DynWalkerAdapter, DynWalkerError, WalkerTypes,
+ any::{TypeName}, effect::{Effect, Future}, higher_ranked_type, hkt::Marker, protocol::{walker::hint::{HintKnown, HintMeta}, Visitor}, symbol::Symbol, DynWalker, DynWalkerAdapter, DynWalkerError, WalkerTypes
};
use super::VisitResult;
@@ -40,28 +34,34 @@ pub trait Tag<'ctx, K: TagKind, E: Effect> {
) -> Future<'a, VisitResult<DynWalker<'a, 'ctx, E>>, E>;
}
-bijective_higher_ranked_type! {
- pub type DynTag['ctx][K, E]: WithContextLt['ctx][]
- for<'a>
- (dyn Tag<'ctx, K, E> + Send + 'a)
- where {
- E: Effect,
- K: TagKind,
- }
-}
+pub struct TagProto<K: TagKind, E: Effect>(Marker<(K, E)>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, K, E] type T['a, 'ctx] for TagProto<K, E> =
+ dyn Tag<'ctx, K, E> + Send + 'a
+ where {
+ K: TagKind,
+ E: Effect,
+ };
-bijective_higher_ranked_type! {
- pub type [][K, E]: TypeName[][]
- for<'ctx>
- (DynTag<'ctx, K, E>)
- where {
- E: Effect,
- K: TagKind,
+ impl['a, 'ctx, K, E] type HigherRanked['a, 'ctx] for dyn Tag<'ctx, K, E> + Send + 'a =
+ TagProto<K, E>
+ where {
+ K: TagKind,
+ E: Effect,
+ };
}
}
-bijective_higher_ranked_type! {
- pub type TagKnownHkt[][]: AnySizedSend[][] for<'lt> (TagKnown)
+higher_ranked_type! {
+ impl HintKnown {
+ impl['a] type T['a] for TagKnown =
+ TagKnown;
+
+ impl['a] type HigherRanked['a] for TagKnown =
+ TagKnown;
+ }
}
pub struct TagKnown {
@@ -72,8 +72,8 @@ pub struct TagHint<K> {
pub kind: K,
}
-impl<'ctx, K, E> HintMeta<'ctx> for DynTag<'ctx, K, E> {
- type Known = TagKnownHkt;
+impl<'ctx, K: TagKind, E: Effect> HintMeta<'ctx> for TagProto<K, E> {
+ type Known = TagKnown;
type Hint = TagHint<K>;
}
@@ -140,14 +140,14 @@ where
let mut walker = DynWalkerAdapter::new(walker);
E::wrap(async move {
- let result = if let Some(object) = visitor.upcast_mut::<DynTag<'ctx, K, E>>() {
+ let result = if let Some(object) = visitor.upcast_mut::<TagProto<K, E>>() {
// The visitor knows about this tag.
// Visit the tag.
object.visit(kind, &mut walker).await
} else if core::any::TypeId::of::<TagDyn>() != core::any::TypeId::of::<K>() {
// Try the dynamic form if we didn't already.
- if let Some(object) = visitor.upcast_mut::<DynTag<'ctx, TagDyn, E>>() {
+ if let Some(object) = visitor.upcast_mut::<TagProto<TagDyn, E>>() {
// The visitor can handle dynamic tags.
// If the visitor can't handle the tag kind then it can call .skip on the walker
// to disable the error for not walking it.
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)
diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs
index b5ebd37..a4d51d5 100644
--- a/src/protocol/walker/hint.rs
+++ b/src/protocol/walker/hint.rs
@@ -5,14 +5,19 @@
//! to the walker about what it is expecting.
use crate::{
- any::{TypeName, WithContextLt},
- bijective_higher_ranked_type,
- effect::{Effect, Future},
- hkt::AnySizedSend,
- protocol::Visitor,
- Flow,
+ any::{TypeName}, effect::{Effect, Future}, higher_ranked_trait, higher_ranked_type, hkt::Marker, protocol::Visitor, Flow
};
+higher_ranked_trait! {
+ pub type class HintKnown for<'a> {
+ type Bound = &'a ();
+
+ type T: { Send + Sized };
+
+ type HigherRanked: { };
+ }
+}
+
/// Meta information for the hint.
///
/// This gives the visitor more information to work from when selecting a hint.
@@ -21,13 +26,13 @@ pub trait HintMeta<'ctx> {
///
/// This should be information easy to get without changing the state of the walker
/// in an irreversible way.
- type Known: AnySizedSend::MemberType;
+ type Known: HintKnown::MemberType;
/// Extra information the visitor can give to the walker about what it is expecting.
type Hint;
}
-pub type Known<'a, 'ctx, Protocol> = AnySizedSend::T<'a, <Protocol as HintMeta<'ctx>>::Known>;
+pub type Known<'a, 'ctx, Protocol> = HintKnown::T<'a, <Protocol as HintMeta<'ctx>>::Known>;
/// Object implementing the [`Hint`] protocol.
pub trait Hint<'ctx, Protocol: ?Sized + HintMeta<'ctx>, E: Effect> {
@@ -47,24 +52,23 @@ pub trait Hint<'ctx, Protocol: ?Sized + HintMeta<'ctx>, E: Effect> {
) -> Future<'a, Result<Known<'a, 'ctx, Protocol>, ()>, E>;
}
-bijective_higher_ranked_type! {
- pub type DynHint['ctx][Protocol, E]: WithContextLt['ctx][]
- for<'a>
- (dyn Hint<'ctx, Protocol, E> + Send + 'a)
- where {
- E: Effect,
- Protocol: ?Sized + WithContextLt::MemberType<'ctx> + 'ctx,
- }
-}
+pub struct HintProto<Protocol: ?Sized, E: Effect>(Marker<(*const Protocol, E)>);
+
+higher_ranked_type! {
+ impl TypeName {
+ impl['a, 'ctx, Protocol, E] type T['a, 'ctx] for HintProto<Protocol, E> =
+ dyn Hint<'ctx, Protocol, E> + Send + 'a
+ where {
+ Protocol: 'static,
+ E: Effect
+ };
-bijective_higher_ranked_type! {
- pub type [][E][Protocol[][]]: TypeName[][]
- for<'ctx>
- (DynHint<'ctx, TypeName::T<'ctx, Protocol>, E>)
- (DynHint<'ctx, Protocol, E>)
- where {
- E: Effect,
- Protocol: ?Sized,
+ impl['a, 'ctx, Protocol, E] type HigherRanked['a, 'ctx] for dyn Hint<'ctx, Protocol, E> + Send + 'a =
+ HintProto<Protocol, E>
+ where {
+ Protocol: 'static,
+ E: Effect,
+ };
}
}
diff --git a/src/walk/walkers/core/struct.rs b/src/walk/walkers/core/struct.rs
index c6a2c8f..21f48bd 100644
--- a/src/walk/walkers/core/struct.rs
+++ b/src/walk/walkers/core/struct.rs
@@ -1,18 +1,16 @@
use core::any::TypeId;
use crate::{
- any::BorrowedStatic,
+ any::{BorrowedStatic, BorrowedStaticHrt},
any_trait,
effect::{Effect, Future},
hkt::Marker,
never::Never,
protocol::{
visitor::{
- visit_recoverable, visit_request_hint, visit_sequence, visit_tag, visit_value,
- DynRecoverable, DynSequence, DynTag, DynValue, RecoverableScope, SequenceKnown,
- SequenceScope, TagConst, TagDyn, TagError, TagHint, TagKnown, ValueKnown, VisitResult,
+ visit_recoverable, visit_request_hint, visit_sequence, visit_tag, visit_value, RecoverableKnown, RecoverableProto, RecoverableScope, SequenceKnown, SequenceProto, SequenceScope, TagConst, TagDyn, TagError, TagHint, TagKnown, TagProto, ValueKnown, ValueProto, VisitResult
},
- walker::hint::{DynHint, HintMeta},
+ walker::hint::{HintMeta, HintProto},
walker::hint::{Hint, Known},
Visitor,
},
@@ -136,22 +134,22 @@ where
any_trait! {
impl['ctx, T, I, M, E] StructWalker<'ctx, T, I, M, E> = [
- DynHint<'ctx, DynRecoverable<'ctx, E>, E>,
- DynHint<'ctx, DynSequence<'ctx, E>, E>,
- DynHint<'ctx, DynValue<'ctx, BorrowedStatic<'ctx, T>, E>, E>,
- DynHint<'ctx, DynTag<'ctx, TagDyn, E>, E>,
- DynHint<'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>, E>,
- DynHint<'ctx, DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>, E>,
- DynHint<'ctx, DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E>, E>,
- DynHint<'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>, E>,
- DynHint<'ctx, DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>, E>,
+ HintProto<RecoverableProto<E>, E>,
+ HintProto<SequenceProto<E>, E>,
+ HintProto<ValueProto<BorrowedStaticHrt<T>, E>, E>,
+ HintProto<TagProto<TagDyn, E>, E>,
+ HintProto<TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>, E>,
+ HintProto<TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>, E>,
+ HintProto<TagProto<TagConst<{ TAG_MAP.to_int() }>, E>, E>,
+ HintProto<TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>, E>,
+ HintProto<TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>, E>,
] where
E: Effect,
T: Sync + 'static,
I: StructTypeInfo<'ctx, M, T = T>
}
-impl<'ctx, T, I, M, E> Hint<'ctx, DynRecoverable<'ctx, E>, E> for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, RecoverableProto<E>, E> for StructWalker<'ctx, T, I, M, E>
where
E: Effect,
I: StructTypeInfo<'ctx, M, T = T>,
@@ -160,7 +158,7 @@ where
fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynRecoverable<'ctx, E> as HintMeta<'ctx>>::Hint,
+ _hint: <RecoverableProto<E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, Flow, E> {
E::map(
visit_recoverable::<E>(visitor, self),
@@ -173,13 +171,13 @@ where
fn known<'a>(
&'a mut self,
- _hint: &'a <DynRecoverable<'ctx, E> as HintMeta<'ctx>>::Hint,
- ) -> Future<'a, Result<Known<'a, 'ctx, DynRecoverable<'ctx, E>>, ()>, E> {
- E::ready(Ok(()))
+ _hint: &'a <RecoverableProto<E> as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, Result<Known<'a, 'ctx, RecoverableProto<E>>, ()>, E> {
+ E::ready(Ok(RecoverableKnown))
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect,
@@ -189,7 +187,7 @@ where
fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E, _>(
@@ -210,12 +208,12 @@ where
fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E> as HintMeta<
+ _hint: &'a <TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E> as HintMeta<
'ctx,
>>::Hint,
) -> Future<
'a,
- Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>, ()>,
+ Result<Known<'a, 'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>, ()>,
E,
> {
E::ready(Ok(TagKnown {
@@ -224,7 +222,7 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect,
@@ -234,7 +232,7 @@ where
fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_TYPE_NAME.to_int() }>, E, _>(
@@ -255,10 +253,10 @@ where
fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: &'a <TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<
'a,
- Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>, ()>,
+ Result<Known<'a, 'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>, ()>,
E,
> {
E::ready(Ok(TagKnown {
@@ -267,7 +265,7 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect,
@@ -277,7 +275,7 @@ where
fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <TagProto<TagConst<{ TAG_MAP.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_MAP.to_int() }>, E, _>(TagConst, visitor, NoopWalker::new()),
@@ -294,8 +292,8 @@ where
fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E> as HintMeta<'ctx>>::Hint,
- ) -> Future<'a, Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E>>, ()>, E>
+ _hint: &'a <TagProto<TagConst<{ TAG_MAP.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, Result<Known<'a, 'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>>, ()>, E>
{
E::ready(Ok(TagKnown {
kind_available: Some(true),
@@ -303,7 +301,7 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect,
@@ -313,7 +311,7 @@ where
fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_STRUCT.to_int() }>, E, _>(
@@ -334,10 +332,10 @@ where
fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: &'a <TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<
'a,
- Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>>, ()>,
+ Result<Known<'a, 'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>>, ()>,
E,
> {
E::ready(Ok(TagKnown {
@@ -346,7 +344,7 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect,
@@ -356,7 +354,7 @@ where
fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_TYPE_ID.to_int() }>, E, _>(
@@ -377,10 +375,10 @@ where
fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: &'a <TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<
'a,
- Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>>, ()>,
+ Result<Known<'a, 'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>>, ()>,
E,
> {
E::ready(Ok(TagKnown {
@@ -389,7 +387,7 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagDyn, E>, E> for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagDyn, E>, E> for StructWalker<'ctx, T, I, M, E>
where
E: Effect,
I: StructTypeInfo<'ctx, M>,
@@ -398,23 +396,23 @@ where
fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- hint: <DynTag<'ctx, TagDyn, E> as HintMeta<'ctx>>::Hint,
+ hint: <TagProto<TagDyn, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, Flow, E> {
match hint.kind.0 {
crate::TAG_TYPE_ID => Hint::<
'ctx,
- DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>,
+ TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>,
E,
>::hint(self, visitor, TagHint { kind: TagConst }),
crate::TAG_STRUCT => {
- Hint::<'ctx, DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>, E>::hint(
+ Hint::<'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>, E>::hint(
self,
visitor,
TagHint { kind: TagConst },
)
}
crate::TAG_MAP => {
- Hint::<'ctx, DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E>, E>::hint(
+ Hint::<'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>, E>::hint(
self,
visitor,
TagHint { kind: TagConst },
@@ -422,12 +420,12 @@ where
}
crate::TAG_TYPE_NAME => Hint::<
'ctx,
- DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>,
+ TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>,
E,
>::hint(self, visitor, TagHint { kind: TagConst }),
crate::TAG_FIELD_NAMES => Hint::<
'ctx,
- DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>,
+ TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>,
E,
>::hint(self, visitor, TagHint { kind: TagConst }),
_ => E::ready(Flow::Continue),
@@ -436,8 +434,8 @@ where
fn known<'a>(
&'a mut self,
- hint: &'a <DynTag<'ctx, TagDyn, E> as HintMeta<'ctx>>::Hint,
- ) -> Future<'a, Result<Known<'a, 'ctx, DynTag<'ctx, TagDyn, E>>, ()>, E> {
+ hint: &'a <TagProto<TagDyn, E> as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, Result<Known<'a, 'ctx, TagProto<TagDyn, E>>, ()>, E> {
E::ready(match hint.kind {
TagDyn(crate::TAG_TYPE_ID) | TagDyn(crate::TAG_STRUCT) => Ok(TagKnown {
kind_available: Some(true),
@@ -449,7 +447,7 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, DynValue<'ctx, BorrowedStatic<'ctx, T>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, ValueProto<BorrowedStaticHrt<T>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect,
@@ -471,7 +469,7 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, DynSequence<'ctx, E>, E> for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, SequenceProto<E>, E> for StructWalker<'ctx, T, I, M, E>
where
E: Effect,
I: StructTypeInfo<'ctx, M, T = T>,
@@ -480,7 +478,7 @@ where
fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynSequence<'ctx, E> as HintMeta<'ctx>>::Hint,
+ _hint: <SequenceProto<E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, Flow, E> {
E::map(visit_sequence::<E>(visitor, self), |status| match status {
VisitResult::Skipped(_) => Flow::Continue,
@@ -490,8 +488,8 @@ where
fn known<'a>(
&'a mut self,
- _hint: &'a <DynSequence<'ctx, E> as HintMeta<'ctx>>::Hint,
- ) -> Future<'a, Result<Known<'a, 'ctx, DynSequence<'ctx, E>>, ()>, E> {
+ _hint: &'a <SequenceProto<E> as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, Result<Known<'a, 'ctx, SequenceProto<E>>, ()>, E> {
let len = I::FIELDS.len();
E::ready(Ok(SequenceKnown {
diff --git a/src/walk/walkers/core/tag.rs b/src/walk/walkers/core/tag.rs
index bc6ba5a..9728b00 100644
--- a/src/walk/walkers/core/tag.rs
+++ b/src/walk/walkers/core/tag.rs
@@ -7,7 +7,7 @@ use crate::{
never::Never,
protocol::{
visitor::{
- visit_request_hint, visit_value, DynSequence, SequenceScope, TagError, VisitResult,
+ visit_request_hint, visit_value, SequenceProto, SequenceScope, TagError, VisitResult
},
Visitor,
},
@@ -62,7 +62,7 @@ where
_ => return Ok(()),
}
- if let Some(object) = visitor.upcast_mut::<DynSequence<'ctx, E>>() {
+ if let Some(object) = visitor.upcast_mut::<SequenceProto<E>>() {
// Visit with the name. Ignore the flow because we return a result not a flow.
let _ = object.visit(&mut self).await;
}
diff --git a/tests/common/protocol/tag.rs b/tests/common/protocol/tag.rs
index 4a31f90..a8f6c35 100644
--- a/tests/common/protocol/tag.rs
+++ b/tests/common/protocol/tag.rs
@@ -2,7 +2,7 @@ use mockall::mock;
use treaty::{
any::any_trait,
effect::{Effect, Future},
- protocol::visitor::{DynTag, Tag, TagKind, VisitResult},
+ protocol::visitor::{TagProto, Tag, TagKind, VisitResult},
DynWalker,
};
@@ -14,7 +14,7 @@ mock! {
any_trait! {
impl['ctx, K, E] MockTagVisitor<K, E> = [
- DynTag<'ctx, K, E>,
+ TagProto<K, E>,
] where
K: TagKind,
E: Effect,
diff --git a/tests/common/protocol/visitor.rs b/tests/common/protocol/visitor.rs
index 652f0b2..b79596d 100644
--- a/tests/common/protocol/visitor.rs
+++ b/tests/common/protocol/visitor.rs
@@ -1,40 +1,40 @@
use mockall::mock;
use treaty::{
- any::{any_trait, TypeName, WithContextLt},
+ any::{any_trait, TypeName},
effect::{Effect, Future},
- protocol::visitor::{DynValue, Value, VisitResult},
+ protocol::visitor::{ValueProto, Value, VisitResult},
Flow,
};
mock! {
- pub ValueVisitor<T: for<'ctx> WithContextLt::MemberType<'ctx>, E>
+ pub ValueVisitor<T: TypeName::MemberType, E>
where
- for<'a, 'ctx> WithContextLt::T<'a, 'ctx, T>: Sized
+ for<'a, 'ctx> TypeName::T<'a, 'ctx, T>: Sized
{
- pub fn visit<'a, 'ctx>(&'a mut self, value: WithContextLt::T<'a, 'ctx, T>) -> VisitResult<()>;
+ pub fn visit<'a, 'ctx>(&'a mut self, value: TypeName::T<'a, 'ctx, T>) -> VisitResult<()>;
}
}
any_trait! {
impl['ctx, T, E] MockValueVisitor<T, E> = [
- DynValue<'ctx, T, E>
+ ValueProto<T, E>
] where
- T: for<'lt> TypeName::LowerType<'lt> + Send + 'ctx,
- for<'a, 'lt> WithContextLt::T<'a, 'lt, T>: Clone + Sized,
+ T: TypeName::MemberType + Send,
+ for<'a, 'b> TypeName::T<'a, 'b, T>: Clone + Sized,
E: Effect,
}
-impl<'ctx, T: for<'lt> WithContextLt::MemberType<'lt>, E: Effect> Value<'ctx, T, E>
+impl<'ctx, T: TypeName::MemberType, E: Effect> Value<'ctx, T, E>
for MockValueVisitor<T, E>
where
- for<'a, 'lt> WithContextLt::T<'a, 'lt, T>: Sized + Clone,
+ for<'a, 'lt> TypeName::T<'a, 'lt, T>: Sized + Clone,
{
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,
+ TypeName::T<'a, 'ctx, T>: Send,
'ctx: 'a,
{
E::ready(match self.visit(value.clone()) {
diff --git a/tests/walkers/core/struct.rs b/tests/walkers/core/struct.rs
index 5ac0926..9ac2d59 100644
--- a/tests/walkers/core/struct.rs
+++ b/tests/walkers/core/struct.rs
@@ -3,7 +3,7 @@ use treaty::{
any::{OwnedStatic, TypeNameId},
effect::{BlockOn, Blocking, Effect, Future, Spin},
protocol::{
- visitor::{DynTag, DynValue, TagConst},
+ visitor::{TagConst, TagProto, ValueProto},
Visitor,
},
walkers::core::{
@@ -71,7 +71,7 @@ fn demo2() {
.expect_traits_mut()
.once()
.with(eq(TypeNameId::of::<
- DynTag<'static, TagConst<{ TAG_STRUCT.to_int() }>, Blocking>,
+ TagProto<TagConst<{ TAG_STRUCT.to_int() }>, Blocking>,
>()))
.in_sequence(&mut seq)
.return_var(Some(Box::new({
@@ -94,7 +94,7 @@ fn demo2() {
.expect_traits_mut()
.once()
.with(eq(TypeNameId::of::<
- DynTag<'static, TagConst<{ TAG_TYPE_NAME.to_int() }>, Blocking>,
+ TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, Blocking>,
>()))
.in_sequence(&mut seq)
.return_var(Some(Box::new({
@@ -107,7 +107,7 @@ fn demo2() {
.expect_traits_mut()
.once()
.with(eq(TypeNameId::of::<
- DynValue<'static, OwnedStatic<&'static str>, Blocking>,
+ ValueProto<OwnedStatic<&'static str>, Blocking>,
>()))
.return_var(Some(Box::new({
let mut mock =