working mocking
Konnor Andrews 2024-04-11
parent 7ba4e87 · commit 58347ea
-rw-r--r--src/any.rs239
-rw-r--r--src/any/static_wrapper.rs116
-rw-r--r--src/build.rs103
-rw-r--r--src/build/builders/core/bool.rs8
-rw-r--r--src/build/builders/debug.rs52
-rw-r--r--src/hkt.rs164
-rw-r--r--src/lib.rs107
-rw-r--r--src/protocol/visitor/recoverable.rs27
-rw-r--r--src/protocol/visitor/request_hint.rs24
-rw-r--r--src/protocol/visitor/sequence.rs27
-rw-r--r--src/protocol/visitor/tag.rs30
-rw-r--r--src/protocol/visitor/value.rs83
-rw-r--r--src/protocol/walker/hint.rs67
-rw-r--r--src/walk/walkers/core/struct.rs167
-rw-r--r--src/walk/walkers/core/tag.rs4
15 files changed, 711 insertions, 507 deletions
diff --git a/src/any.rs b/src/any.rs
index 4cd533c..ed6c1ef 100644
--- a/src/any.rs
+++ b/src/any.rs
@@ -19,9 +19,9 @@
//! without unsafe code. However, its recommended to use the provided [`nameable`]
//! macro when possible.
-// pub mod static_wrapper;
+pub mod static_wrapper;
-use crate::bijective_higher_ranked_trait;
+use crate::{bijective_higher_ranked_trait, bijective_higher_ranked_type};
use core::{
marker::{PhantomData, PhantomPinned},
mem::{ManuallyDrop, MaybeUninit},
@@ -38,165 +38,67 @@ bijective_higher_ranked_trait! {
pub type class TypeName[][]: {'static} [for<'lt> MaybeSized::Trait<'lt>]
}
-// trait Other<'lt> {}
-//
-// trait Demo<'lt> {
-// fn demo(&self) -> &'lt i32;
-// }
-//
-// bijective_higher_ranked_type! {
-// type DynDemo['lt][]: (MaybeSized)['lt][] = for<'a> dyn Demo<'lt> + 'a
-// }
-//
-// bijective_higher_ranked_type! {
-// type DemoName[][]: (TypeName)[][] = for<'lt> DynDemo<'lt>
-// }
-
-// bijective_higher_ranked_type! {
-// pub type MaybeSizedRef['lt][T]: (MaybeSized)['lt][] = for<'a> &'lt T where { T: 'lt }
-// }
-
-const _: () = {
- pub struct Name<T: ?Sized>(PhantomData<fn() -> *const T>);
- pub struct LowerName<'lt, T: ?Sized>(PhantomData<fn() -> (&'lt (), *const T)>);
-
- impl<'a, 'lt, T: ?Sized + MaybeSized::LowerForLt<'a, 'lt, &'a (&'lt (),)>>
- MaybeSized::LowerForLt<'a, 'lt, &'a (&'lt (),)> for LowerName<'lt, T>
- {
- type T = &'a <T as MaybeSized::LowerForLt<'a, 'lt, &'a (&'lt (),)>>::T;
- }
-
- impl<'a, 'lt, T: ?Sized + MaybeSized::RaiseForLt<'a, 'lt, &'a (&'lt (),)>>
- MaybeSized::RaiseForLt<'a, 'lt, &'a (&'lt (),)> for &'a T
- {
- type HigherRanked =
- LowerName<'lt, <T as MaybeSized::RaiseForLt<'a, 'lt, &'a (&'lt (),)>>::HigherRanked>;
- }
-
- impl<'lt, T: ?Sized + TypeName::LowerForLt<'lt, &'lt ()>> TypeName::LowerForLt<'lt, &'lt ()>
- for Name<T>
- {
- type T = LowerName<'lt, <T as TypeName::LowerForLt<'lt, &'lt ()>>::T>;
- }
-
- impl<'lt, T: ?Sized + 'lt + TypeName::RaiseForLt<'lt, &'lt ()>>
- TypeName::RaiseForLt<'lt, &'lt ()> for LowerName<'lt, T>
- {
- type HigherRanked = Name<TypeName::HigherRanked<'lt, T>>;
- }
-};
-
-const _: () = {
- pub struct Name<T: ?Sized>(PhantomData<fn() -> *const T>);
- pub struct LowerName<'lt, T: ?Sized>(PhantomData<fn() -> (&'lt (), *const T)>);
-
- impl<'a, 'lt, T: ?Sized + MaybeSized::LowerForLt<'a, 'lt, &'a (&'lt (),)>>
- MaybeSized::LowerForLt<'a, 'lt, &'a (&'lt (),)> for LowerName<'lt, T>
- {
- type T = &'a mut <T as MaybeSized::LowerForLt<'a, 'lt, &'a (&'lt (),)>>::T;
+bijective_higher_ranked_type! {
+ pub type DynRef['lt][][T['lt][]]: MaybeSized['lt][]
+ for<'a>
+ (&'a MaybeSized::T<'a, 'lt, T>)
+ (&'a T)
+ where {
+ T: ?Sized
}
+}
- impl<'a, 'lt, T: ?Sized + MaybeSized::RaiseForLt<'a, 'lt, &'a (&'lt (),)>>
- MaybeSized::RaiseForLt<'a, 'lt, &'a (&'lt (),)> for &'a mut T
- {
- type HigherRanked =
- LowerName<'lt, <T as MaybeSized::RaiseForLt<'a, 'lt, &'a (&'lt (),)>>::HigherRanked>;
+bijective_higher_ranked_type! {
+ pub type [][][T[][]]: TypeName[][]
+ for<'lt>
+ (DynRef<'lt, TypeName::T<'lt, T>>)
+ (DynRef<'lt, T>)
+ where {
+ T: ?Sized
}
+}
- impl<'lt, T: ?Sized + TypeName::LowerForLt<'lt, &'lt ()>> TypeName::LowerForLt<'lt, &'lt ()>
- for Name<T>
- {
- type T = LowerName<'lt, <T as TypeName::LowerForLt<'lt, &'lt ()>>::T>;
+bijective_higher_ranked_type! {
+ pub type DynMut['lt][][T['lt][]]: MaybeSized['lt][]
+ for<'a>
+ (&'a mut MaybeSized::T<'a, 'lt, T>)
+ (&'a mut T)
+ where {
+ T: ?Sized
}
+}
- impl<'lt, T: ?Sized + 'lt + TypeName::RaiseForLt<'lt, &'lt ()>>
- TypeName::RaiseForLt<'lt, &'lt ()> for LowerName<'lt, T>
- {
- type HigherRanked = Name<TypeName::HigherRanked<'lt, T>>;
+bijective_higher_ranked_type! {
+ pub type [][][T[][]]: TypeName[][]
+ for<'lt>
+ (DynMut<'lt, TypeName::T<'lt, T>>)
+ (DynMut<'lt, T>)
+ where {
+ T: ?Sized
}
-};
+}
#[cfg(feature = "alloc")]
-const _: () = {
- pub struct Name<T: ?Sized>(PhantomData<fn() -> *const T>);
- pub struct LowerName<'lt, T: ?Sized>(PhantomData<fn() -> (&'lt (), *const T)>);
-
- impl<'a, 'lt, T: ?Sized + MaybeSized::LowerForLt<'a, 'lt, &'a (&'lt (),)>>
- MaybeSized::LowerForLt<'a, 'lt, &'a (&'lt (),)> for LowerName<'lt, T>
- {
- type T = Box<<T as MaybeSized::LowerForLt<'a, 'lt, &'a (&'lt (),)>>::T>;
- }
-
- impl<'a, 'lt, T: ?Sized + MaybeSized::RaiseForLt<'a, 'lt, &'a (&'lt (),)>>
- MaybeSized::RaiseForLt<'a, 'lt, &'a (&'lt (),)> for Box<T>
- {
- type HigherRanked =
- LowerName<'lt, <T as MaybeSized::RaiseForLt<'a, 'lt, &'a (&'lt (),)>>::HigherRanked>;
- }
-
- impl<'lt, T: ?Sized + TypeName::LowerForLt<'lt, &'lt ()>> TypeName::LowerForLt<'lt, &'lt ()>
- for Name<T>
- {
- type T = LowerName<'lt, <T as TypeName::LowerForLt<'lt, &'lt ()>>::T>;
+bijective_higher_ranked_type! {
+ pub type DynBox['lt][][T['lt][]]: MaybeSized['lt][]
+ for<'a>
+ (Box<MaybeSized::T<'a, 'lt, T>>)
+ (Box<T>)
+ where {
+ T: ?Sized
}
+}
- impl<'lt, T: ?Sized + 'lt + TypeName::RaiseForLt<'lt, &'lt ()>>
- TypeName::RaiseForLt<'lt, &'lt ()> for LowerName<'lt, T>
- {
- type HigherRanked = Name<TypeName::HigherRanked<'lt, T>>;
+#[cfg(feature = "alloc")]
+bijective_higher_ranked_type! {
+ pub type [][][T[][]]: TypeName[][]
+ for<'lt>
+ (DynBox<'lt, TypeName::T<'lt, T>>)
+ (DynBox<'lt, T>)
+ where {
+ T: ?Sized
}
-};
-
-// nameable! {
-// pub struct Name['a, 'lt, T];
-// impl [T::ForLtName] for &'lt T where {
-// T: TypeNameableForLt<'a, 'lt, &'a &'lt ()> + ?Sized
-// }
-// impl [T] where &'lt T::ForLtNameable {
-// T: TypeNameForLt<'a, 'lt, &'a &'lt ()> + ?Sized, T::ForLtNameable: 'lt
-// }
-// }
-
-// nameable! {
-// pub struct Name['a, 'lt, T];
-// impl [<T as TypeNameableHelper<'lt>>::Name] for &'lt mut T where {
-// T: TypeNameable<'lt> + ?Sized
-// }
-// impl [T] where &'lt mut T::Nameable {
-// T: TypeNameForLt<'a, 'lt, &'a &'lt ()> + ?Sized, T::Nameable: 'lt
-// }
-// }
-//
-// nameable! {
-// pub struct Name['a, 'lt, T];
-// impl [<T as TypeNameableHelper<'lt>>::Name] for *const T where {
-// T: TypeNameable<'lt> + ?Sized
-// }
-// impl [T] where *const T::Nameable {
-// T: TypeNameForLt<'a, 'lt, &'a &'lt ()> + ?Sized
-// }
-// }
-//
-// nameable! {
-// pub struct Name['a, 'lt, T];
-// impl [<T as TypeNameableHelper<'lt>>::Name] for *mut T where {
-// T: TypeNameable<'lt> + ?Sized
-// }
-// impl [T] where *mut T::Nameable {
-// T: TypeNameForLt<'a, 'lt, &'a &'lt ()> + ?Sized
-// }
-// }
-//
-// #[cfg(feature = "alloc")]
-// nameable! {
-// pub struct Name['a, 'lt, T];
-// impl [<T as TypeNameableHelper<'lt>>::Name] for Box<T> where {
-// T: TypeNameable<'lt> + ?Sized
-// }
-// impl [T] where Box<T::Nameable> {
-// T: TypeNameForLt<'a, 'lt, &'a &'lt ()> + ?Sized
-// }
-// }
+}
/// [`TypeId`][core::any::TypeId] with a lifetime generic `'lt`.
///
@@ -370,7 +272,10 @@ pub trait AnyTrait<'lt> {
/// If `self` doesn't support upcasting to the requested type
/// then `None` is returned. The returned trait object is type erased so this trait
/// is object safe.
- fn upcast_to_id_mut<'a>(&'a mut self, id: LtTypeId<'lt>) -> Option<IndirectLtAny<'a, 'lt, Mut>>
+ fn upcast_to_id_mut<'a: 'b, 'b>(
+ &'a mut self,
+ id: LtTypeId<'lt>,
+ ) -> Option<IndirectLtAny<'b, 'lt, Mut>>
where
'lt: 'a;
}
@@ -427,22 +332,22 @@ impl<'lt> dyn AnyTrait<'lt> + Send + '_ {
#[macro_export]
macro_rules! any_trait {
{
- impl[$a:lifetime, $lt:lifetime $($generic:tt)*] $name:ty = [$($protocol:ty),* $(,)?] $(else $fallback:path)? $(where $($bound:tt)*)?
+ impl[$lt:lifetime $($generic:tt)*] $name:ty = [$($protocol:ty),* $(,)?] $(else $fallback:path)? $(where $($bound:tt)*)?
} => {
impl<$lt $($generic)*> $crate::any::AnyTrait<$lt> for $name
$(where $($bound)*)?
{
#[inline]
- fn upcast_to_id<$a>(
- &$a self,
+ fn upcast_to_id<'__>(
+ &'__ self,
id: $crate::any::LtTypeId<$lt>
- ) -> ::core::option::Option<$crate::any::IndirectLtAny<$a, $lt, $crate::any::Ref>>
+ ) -> ::core::option::Option<$crate::any::IndirectLtAny<'__, $lt, $crate::any::Ref>>
where
- $lt: $a
+ $lt: '__
{
match id {
$(id if id == $crate::any::LtTypeId::of::<$protocol>()
- => ::core::option::Option::Some($crate::any::IndirectLtAny::<$a, $lt, _>::new::<$protocol>(self as _)),)*
+ => ::core::option::Option::Some($crate::any::IndirectLtAny::<'__, $lt, _>::new::<$protocol>(self as _)),)*
_ => {
$($fallback(id);)?
::core::option::Option::None
@@ -451,16 +356,16 @@ macro_rules! any_trait {
}
#[inline]
- fn upcast_to_id_mut<$a>(
- &$a mut self,
+ fn upcast_to_id_mut<'__: '___, '___>(
+ &'__ mut self,
id: $crate::any::LtTypeId<$lt>
- ) -> ::core::option::Option<$crate::any::IndirectLtAny<$a, $lt, $crate::any::Mut>>
+ ) -> ::core::option::Option<$crate::any::IndirectLtAny<'___, $lt, $crate::any::Mut>>
where
- $lt: $a
+ $lt: '__
{
match id {
$(id if id == $crate::any::LtTypeId::of::<$protocol>()
- => ::core::option::Option::Some($crate::any::IndirectLtAny::<$a, $lt, _>::new::<$protocol>(self as _)),)*
+ => ::core::option::Option::Some($crate::any::IndirectLtAny::<'___, $lt, _>::new::<$protocol>(self as _)),)*
_ => {
$($fallback(id);)?
::core::option::Option::None
@@ -485,7 +390,11 @@ pub use any_trait;
pub struct IndirectLtAny<'a, 'lt: 'a, I: Indirect<'a>> {
info: fn() -> (LtTypeId<'lt>, unsafe fn(RawIndirect)),
indirect: RawIndirect,
- _marker: PhantomData<(I::ForT<fn(&'lt ()) -> &'lt ()>, PhantomPinned, *const ())>,
+ _marker: PhantomData<(
+ I::ForT<fn(&'lt (), &'a ()) -> (&'lt (), &'a ())>,
+ PhantomPinned,
+ *const (),
+ )>,
}
impl<'a, 'lt, I: Indirect<'a>> Drop for IndirectLtAny<'a, 'lt, I> {
@@ -671,11 +580,11 @@ mod test {
}
bijective_higher_ranked_type! {
- type DynZ['ctx][]: (MaybeSized)['ctx][] = for<'a> dyn Z<'ctx> + 'a
+ type DynZ['ctx][]: MaybeSized['ctx][] for<'a> (dyn Z<'ctx> + 'a)
}
bijective_higher_ranked_type! {
- type [][]: (TypeName)[][] = for<'lt> DynZ<'lt>
+ type [][]: TypeName[][] for<'lt> (DynZ<'lt>)
}
struct X<'ctx>(&'ctx i32);
@@ -687,7 +596,7 @@ mod test {
}
any_trait! {
- impl['a, 'ctx] X<'ctx> = [
+ impl['ctx] X<'ctx> = [
DynZ<'ctx>
]
}
diff --git a/src/any/static_wrapper.rs b/src/any/static_wrapper.rs
index dee90d6..fb719e0 100644
--- a/src/any/static_wrapper.rs
+++ b/src/any/static_wrapper.rs
@@ -3,48 +3,114 @@
use super::*;
/// Impl of [`TypeNameable`] for `'static` types that are owned (`T`).
+#[derive(PartialEq, Clone, Copy, Debug)]
#[repr(transparent)]
pub struct OwnedStatic<T: ?Sized>(pub T);
-nameable! {
- pub struct Name['a, 'lt, T];
- impl [T] for OwnedStatic<T> where { T: ?Sized + 'static }
+bijective_higher_ranked_type! {
+ pub type DynOwnedStatic['lt][T][]: MaybeSized['lt][]
+ for<'a>
+ (OwnedStatic<T>)
+ where {
+ T: ?Sized + 'lt
+ }
+}
+
+bijective_higher_ranked_type! {
+ pub type [][T][]: TypeName[][]
+ for<'lt>
+ (DynOwnedStatic<'lt, T>)
+ where {
+ T: ?Sized + 'static
+ }
}
/// Impl of [`TypeNameable`] for `'static` types that are borrowed (`&'lt T`).
#[repr(transparent)]
pub struct BorrowedStatic<'lt, T: ?Sized>(pub &'lt T);
-nameable! {
- pub struct Name['a, 'lt, T];
- impl [T] for BorrowedStatic<'lt, T> where { T: ?Sized + 'static }
+bijective_higher_ranked_type! {
+ pub type DynBorrowedStatic['lt][T]: MaybeSized['lt][]
+ for<'a>
+ (BorrowedStatic<'lt, T>)
+ where {
+ T: ?Sized + 'lt,
+ }
+}
+
+bijective_higher_ranked_type! {
+ pub type [][T][]: TypeName[][]
+ for<'lt>
+ (DynBorrowedStatic<'lt, T>)
+ where {
+ T: ?Sized + 'static
+ }
}
/// Impl of [`TypeNameable`] for `'static` types that are temporarily borrowed (`&'a T`).
#[repr(transparent)]
pub struct TempBorrowedStatic<'a, T: ?Sized>(pub &'a T);
-nameable! {
- pub struct Name['a, 'lt, T];
- impl [T] for TempBorrowedStatic<'a, T> where { T: ?Sized + 'static }
+bijective_higher_ranked_type! {
+ pub type DynTempBorrowedStatic['lt][T]: MaybeSized['lt][]
+ for<'a>
+ (TempBorrowedStatic<'a, T>)
+ where {
+ T: ?Sized + 'lt,
+ }
+}
+
+bijective_higher_ranked_type! {
+ pub type [][T][]: TypeName[][]
+ for<'lt>
+ (DynTempBorrowedStatic<'lt, T>)
+ where {
+ T: ?Sized + 'static
+ }
}
/// Impl of [`TypeNameable`] for `'static` types that are borrowed mutably (`&'lt mut T`).
#[repr(transparent)]
pub struct BorrowedMutStatic<'lt, T: ?Sized>(pub &'lt mut T);
-nameable! {
- pub struct Name['a, 'lt, T];
- impl [T] for BorrowedMutStatic<'lt, T> where { T: ?Sized + 'static }
+bijective_higher_ranked_type! {
+ pub type DynBorrowedMutStatic['lt][T]: MaybeSized['lt][]
+ for<'a>
+ (BorrowedMutStatic<'lt, T>)
+ where {
+ T: ?Sized + 'lt,
+ }
+}
+
+bijective_higher_ranked_type! {
+ pub type [][T][]: TypeName[][]
+ for<'lt>
+ (DynBorrowedMutStatic<'lt, T>)
+ where {
+ T: ?Sized + 'static
+ }
}
/// Impl of [`TypeNameable`] for `'static` types that are temporarily borrowed mutably (`&'a mut T`).
#[repr(transparent)]
pub struct TempBorrowedMutStatic<'a, T: ?Sized>(pub &'a mut T);
-nameable! {
- pub struct Name['a, 'lt, T];
- impl [T] for TempBorrowedMutStatic<'a, T> where { T: ?Sized + 'static }
+bijective_higher_ranked_type! {
+ pub type DynTempBorrowedMutStatic['lt][T]: MaybeSized['lt][]
+ for<'a>
+ (TempBorrowedMutStatic<'a, T>)
+ where {
+ T: ?Sized + 'lt,
+ }
+}
+
+bijective_higher_ranked_type! {
+ pub type [][T][]: TypeName[][]
+ for<'lt>
+ (DynTempBorrowedMutStatic<'lt, T>)
+ where {
+ T: ?Sized + 'static
+ }
}
/// Impl of [`TypeNameable`] for `'static` types that are in a [`Box`] (`Box<T>`).
@@ -52,9 +118,23 @@ nameable! {
pub struct BoxedStatic<T: ?Sized>(pub Box<T>);
#[cfg(feature = "alloc")]
-nameable! {
- pub struct Name['a, 'lt, T];
- impl [T] for BoxedStatic<T> where { T: ?Sized + 'static }
+bijective_higher_ranked_type! {
+ pub type DynBoxedStatic['lt][T]: MaybeSized['lt][]
+ for<'a>
+ (BoxedStatic<T>)
+ where {
+ T: ?Sized + 'lt,
+ }
+}
+
+#[cfg(feature = "alloc")]
+bijective_higher_ranked_type! {
+ pub type [][T][]: TypeName[][]
+ for<'lt>
+ (DynBoxedStatic<'lt, T>)
+ where {
+ T: ?Sized + 'static
+ }
}
#[derive(Debug)]
diff --git a/src/build.rs b/src/build.rs
index 0f70423..f116bcb 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -55,10 +55,19 @@ pub trait Builder<'ctx, E: Effect<'ctx>>: BuilderTypes + Sized + Send {
#[cfg(test)]
pub mod test {
- use std::{collections::HashMap, sync::{Mutex, MutexGuard, PoisonError}};
+ use std::{
+ collections::HashMap,
+ sync::{Mutex, MutexGuard, PoisonError},
+ };
use crate::{
- any::{static_wrapper::OwnedStatic, AnyTrait, Indirect, IndirectLtAny, LtTypeId, Mut, Ref, TypeNameable}, effect::{BlockOn, Blocking, Spin}, protocol::visitor::value::{DynValue, Value}, Flow
+ any::{
+ static_wrapper::{DynOwnedStatic, OwnedStatic},
+ AnyTrait, Boxed, Indirect, IndirectLtAny, LtTypeId, MaybeSized, Mut, Ref, TypeName,
+ },
+ effect::{BlockOn, Blocking, Spin},
+ protocol::visitor::value::{DynValue, Value},
+ Flow,
};
use super::*;
@@ -87,21 +96,41 @@ pub mod test {
pub type MockBuilder<Seed = (), Value = (), Error = ()> = mock::MockBuilder<Seed, Value, Error>;
- trait MockIndirect: Send {
+ pub trait MockIndirect: Send {
fn indirect(&self) -> IndirectLtAny<'_, 'static, Ref>;
- fn indirect_mut(&mut self) -> IndirectLtAny<'_, 'static, Mut>;
+ fn indirect_mut<'a: 'b, 'b>(&'a mut self) -> IndirectLtAny<'b, 'static, Mut>;
}
- impl<T: ?Sized + for<'a> TypeNameable<'a, 'static> + Send> MockIndirect for Box<T> {
+ impl MockIndirect for MockValueVisitor {
fn indirect(&self) -> IndirectLtAny<'_, 'static, Ref> {
- IndirectLtAny::new(self)
+ IndirectLtAny::new::<DynValue<'static, DynOwnedStatic<'static, i32>, Blocking>>(
+ self as _,
+ )
}
- fn indirect_mut(&mut self) -> IndirectLtAny<'_, 'static, Mut> {
- IndirectLtAny::new(self)
+ fn indirect_mut<'a: 'b, 'b>(&'a mut self) -> IndirectLtAny<'b, 'static, Mut> {
+ IndirectLtAny::<'b, 'static, Mut>::new::<
+ DynValue<'static, DynOwnedStatic<'static, i32>, Blocking>,
+ >(self as _)
}
}
+ // pub struct IndirectBox<'a, 'ctx>(IndirectLtAny<'a, 'ctx, Boxed>);
+ //
+ // impl MockIndirect for IndirectBox
+ // {
+ // fn indirect<'a>(&'a self) -> IndirectLtAny<'a, 'static, Ref> {
+ // // let x: &MaybeSized::T<'a, 'static, T> = &*self.0;
+ // // IndirectLtAny::<'a, 'static, Ref>::new::<T>(x)
+ // todo!()
+ // }
+ //
+ // fn indirect_mut<'a>(&'a mut self) -> IndirectLtAny<'a, 'static, Mut> {
+ // let x: &'a mut MaybeSized::T<'static, 'static, T> = &mut *self.0;
+ // IndirectLtAny::<'static, 'static, Mut>::new::<T>(x)
+ // }
+ // }
+
impl<Seed: Send, Value: Send, Error: Send> BuilderTypes for MockBuilder<Seed, Value, Error> {
type Seed = Seed;
@@ -117,7 +146,9 @@ pub mod test {
}
}
- impl<Seed: Send, Value: Send, Error: Send, E: Effect<'static>> Builder<'static, E> for MockBuilder<Seed, Value, Error> {
+ impl<Seed: Send, Value: Send, Error: Send, E: Effect<'static>> Builder<'static, E>
+ for MockBuilder<Seed, Value, Error>
+ {
fn from_seed<'a>(seed: Self::Seed) -> Future<'a, 'static, Self, E>
where
Self: 'a,
@@ -148,10 +179,10 @@ pub mod test {
self.lookup().get(&id).map(|x| x.indirect())
}
- fn upcast_to_id_mut<'a>(
+ fn upcast_to_id_mut<'a: 'b, 'b>(
&'a mut self,
id: LtTypeId<'static>,
- ) -> Option<IndirectLtAny<'a, 'static, Mut>>
+ ) -> Option<IndirectLtAny<'b, 'static, Mut>>
where
'static: 'a,
{
@@ -165,7 +196,7 @@ pub mod test {
}
}
- impl<'ctx, E: Effect<'ctx>> Value<'ctx, OwnedStatic<i32>, E> for MockValueVisitor {
+ impl<'ctx, E: Effect<'ctx>> Value<'ctx, DynOwnedStatic<'ctx, i32>, E> for MockValueVisitor {
fn visit<'a>(&'a mut self, value: OwnedStatic<i32>) -> Future<'a, 'ctx, Flow, E> {
E::ready(self.private_visit(value))
}
@@ -176,40 +207,64 @@ pub mod test {
let _lock = MockBuilder::<(), (), ()>::lock_context();
let ctx = MockBuilder::<(), (), ()>::private_from_seed_context();
+ // Expect one mock builder to be made from the from_seed static method;
ctx.expect().once().returning(|_| {
let mut mock = MockBuilder::new();
- mock.expect_lookup_mut().returning(|| {
- let mut map = HashMap::<_, Box<dyn MockIndirect>>::new();
+ // Expect that we will lookup one trait on the visitor.
+ mock.expect_lookup_mut().once().returning(|| {
+ let mut map = HashMap::<LtTypeId<'static>, Box<dyn MockIndirect>>::new();
+
+ let mut mock = MockValueVisitor::new();
+
+ // Expect that we will pass the value 42 to the visitor.
+ mock.expect_private_visit()
+ .once()
+ .with(eq(OwnedStatic(42)))
+ .return_const(Flow::Done);
+ // This mock will be for the value protocol.
map.insert(
- LtTypeId::of::<DynValue<'_, 'static, OwnedStatic<i32>, Blocking>>(),
- Box::new(Box::new(MockValueVisitor::new()) as Box<DynValue<'_, 'static, OwnedStatic<i32>, Blocking>>)
+ LtTypeId::of::<DynValue<'static, DynOwnedStatic<'static, i32>, Blocking>>(),
+ Box::new(mock),
);
map
});
- mock.expect_private_build().once().returning(|| {
- Ok(())
- });
+ mock.expect_private_build().once().returning(|| Ok(()));
mock
});
+ // Create a mock builder using the static from_seed method.
let mut builder = Spin::block_on(<MockBuilder as Builder<Blocking>>::from_seed(()));
{
+ // Get the mock builder as a visitor.
let visitor = <MockBuilder as Builder<Blocking>>::as_visitor(&mut builder);
- let x = visitor.upcast_to_id_mut(LtTypeId::of::<DynValue<'_, '_, OwnedStatic<i32>, Blocking>>()).unwrap();
- let Ok(x) = x.downcast::<DynValue<'_, '_, OwnedStatic<i32>, Blocking>>() else {
+ // Upcast the mock visitor into a trait object for the value protocol.
+ // This resolves to one of the values in the hashmap above and not the builder itself.
+ let x = visitor
+ .upcast_to_id_mut(LtTypeId::of::<
+ DynValue<'_, DynOwnedStatic<'_, i32>, Blocking>,
+ >())
+ .unwrap();
+
+ // Finish the upcast by downcasting to the trait object.
+ let Ok(x) = x.downcast::<DynValue<'_, DynOwnedStatic<'_, i32>, Blocking>>() else {
panic!();
};
- Spin::block_on(x.visit(OwnedStatic(42)));
+
+ // Use the visit method on the mock visitor.
+ assert_eq!(Spin::block_on(x.visit(OwnedStatic(42))), Flow::Done);
}
- let x = <MockBuilder as Builder<Blocking>>::build(builder);
- todo!();
+ // Finish building the mock builder.
+ assert_eq!(
+ Spin::block_on(<MockBuilder as Builder<Blocking>>::build(builder)).unwrap(),
+ ()
+ );
}
}
diff --git a/src/build/builders/core/bool.rs b/src/build/builders/core/bool.rs
index e00e674..346441e 100644
--- a/src/build/builders/core/bool.rs
+++ b/src/build/builders/core/bool.rs
@@ -1,7 +1,7 @@
use core::{marker::PhantomData, ops::ControlFlow};
use crate::{
- any::static_wrapper::OwnedStatic,
+ any::static_wrapper::{DynOwnedStatic, OwnedStatic},
any_trait,
effect::{Effect, Future},
protocol::{
@@ -60,12 +60,12 @@ impl<'ctx, E: Effect<'ctx>> crate::Builder<'ctx, E> for Builder<E> {
}
any_trait! {
- impl['a, 'ctx, E] Builder<E> = [
- DynValue<'a, 'ctx, OwnedStatic<bool>, E>,
+ impl['ctx, E] Builder<E> = [
+ DynValue<'ctx, DynOwnedStatic<'ctx, bool>, E>,
] where E: Effect<'ctx>
}
-impl<'ctx, E: Effect<'ctx>> Value<'ctx, OwnedStatic<bool>, E> for Builder<E> {
+impl<'ctx, E: Effect<'ctx>> Value<'ctx, DynOwnedStatic<'ctx, bool>, E> for Builder<E> {
#[inline]
fn visit<'a>(&'a mut self, OwnedStatic(value): OwnedStatic<bool>) -> Future<'a, 'ctx, Flow, E> {
self.0 = Some(value);
diff --git a/src/build/builders/debug.rs b/src/build/builders/debug.rs
index 4957ba9..2914423 100644
--- a/src/build/builders/debug.rs
+++ b/src/build/builders/debug.rs
@@ -1,7 +1,10 @@
use core::{any::TypeId, marker::PhantomData, ops::ControlFlow};
use crate::{
- any::{static_wrapper::OwnedStatic, LtTypeId},
+ any::{
+ static_wrapper::{DynOwnedStatic, OwnedStatic},
+ LtTypeId,
+ },
any_trait,
effect::{Effect, Future},
never::Never,
@@ -21,16 +24,16 @@ use crate::{
pub struct Visitor<E>(usize, PhantomData<fn() -> E>);
any_trait! {
- impl['a, 'ctx, E] Visitor<E> = [
- DynRequestHint<'a, 'ctx, E>,
+ impl['ctx, E] Visitor<E> = [
+ DynRequestHint<'ctx, E>,
// DynRecoverable<'a, 'ctx, E>,
- DynTag<'a, 'ctx, TagDyn, E>,
- DynValue<'a, 'ctx, OwnedStatic<&'static str>, E>,
- DynValue<'a, 'ctx, OwnedStatic<TypeId>, E>,
- DynValue<'a, 'ctx, OwnedStatic<usize>, E>,
- DynValue<'a, 'ctx, OwnedStatic<bool>, E>,
+ DynTag<'ctx, TagDyn, E>,
+ DynValue<'ctx, DynOwnedStatic<'ctx, &'static str>, E>,
+ DynValue<'ctx, DynOwnedStatic<'ctx, TypeId>, E>,
+ DynValue<'ctx, DynOwnedStatic<'ctx, usize>, E>,
+ DynValue<'ctx, DynOwnedStatic<'ctx, bool>, E>,
// DynValue<'a, 'ctx, OwnedStatic<&'static [&'static str]>, E>,
- DynSequence<'a, 'ctx, E>,
+ DynSequence<'ctx, E>,
] else fallback where E: Effect<'ctx>
}
@@ -109,53 +112,54 @@ impl<'ctx, E: Effect<'ctx>> Tag<'ctx, TagDyn, E> for Visitor<E> {
}
}
-impl<'ctx, E: Effect<'ctx>> Value<'ctx, OwnedStatic<&'static str>, E> for Visitor<E> {
+impl<'ctx, E: Effect<'ctx>> Value<'ctx, DynOwnedStatic<'ctx, &'static str>, E> for Visitor<E> {
fn visit<'a>(
&'a mut self,
OwnedStatic(value): OwnedStatic<&'static str>,
- ) -> Future<'a, 'ctx, Flow, E>
- {
+ ) -> Future<'a, 'ctx, Flow, E> {
self.tab();
println!("{:?}", value);
E::ready(Flow::Continue)
}
}
-impl<'ctx, E: Effect<'ctx>> Value<'ctx, OwnedStatic<usize>, E> for Visitor<E> {
- fn visit<'a>(&'a mut self, OwnedStatic(value): OwnedStatic<usize>) -> Future<'a, 'ctx, Flow, E>
- {
+impl<'ctx, E: Effect<'ctx>> Value<'ctx, DynOwnedStatic<'ctx, usize>, E> for Visitor<E> {
+ fn visit<'a>(
+ &'a mut self,
+ OwnedStatic(value): OwnedStatic<usize>,
+ ) -> Future<'a, 'ctx, Flow, E> {
self.tab();
println!("{}", value);
E::ready(Flow::Continue)
}
}
-impl<'ctx, E: Effect<'ctx>> Value<'ctx, OwnedStatic<bool>, E> for Visitor<E> {
- fn visit<'a>(&'a mut self, OwnedStatic(value): OwnedStatic<bool>) -> Future<'a, 'ctx, Flow, E>
- {
+impl<'ctx, E: Effect<'ctx>> Value<'ctx, DynOwnedStatic<'ctx, bool>, E> for Visitor<E> {
+ fn visit<'a>(&'a mut self, OwnedStatic(value): OwnedStatic<bool>) -> Future<'a, 'ctx, Flow, E> {
self.tab();
println!("{}", value);
E::ready(Flow::Continue)
}
}
-impl<'ctx, E: Effect<'ctx>> Value<'ctx, OwnedStatic<&'static [&'static str]>, E>
+impl<'ctx, E: Effect<'ctx>> Value<'ctx, DynOwnedStatic<'ctx, &'static [&'static str]>, E>
for Visitor<E>
{
fn visit<'a>(
&'a mut self,
OwnedStatic(value): OwnedStatic<&'static [&'static str]>,
- ) -> Future<'a, 'ctx, Flow, E>
- {
+ ) -> Future<'a, 'ctx, Flow, E> {
self.tab();
println!("{:?}", value);
E::ready(Flow::Continue)
}
}
-impl<'ctx, E: Effect<'ctx>> Value<'ctx, OwnedStatic<TypeId>, E> for Visitor<E> {
- fn visit<'a>(&'a mut self, OwnedStatic(value): OwnedStatic<TypeId>) -> Future<'a, 'ctx, Flow, E>
- {
+impl<'ctx, E: Effect<'ctx>> Value<'ctx, DynOwnedStatic<'ctx, TypeId>, E> for Visitor<E> {
+ fn visit<'a>(
+ &'a mut self,
+ OwnedStatic(value): OwnedStatic<TypeId>,
+ ) -> Future<'a, 'ctx, Flow, E> {
self.tab();
println!("Visit type ID: {:?}", value);
E::ready(Flow::Continue)
diff --git a/src/hkt.rs b/src/hkt.rs
index 3f2c52d..58539db 100644
--- a/src/hkt.rs
+++ b/src/hkt.rs
@@ -121,14 +121,14 @@ macro_rules! bijective_higher_ranked_trait {
where $($($bound)*)? $($($for_bound)*)?
{
- type T: ?Sized + RaiseForLt<$lt, $($lifetimes,)* B, $($generic),*> $(+ $($provides)+)? + $lt;
+ type T: ?Sized + RaiseForLt<$lt, $($lifetimes,)* B, $($generic,)* HigherRanked = Self> $(+ $($provides)+)? + $lt;
}
pub trait RaiseForLt<$lt, $($lifetimes,)* B, $($generic),*>
where $($($bound)*)? $($($for_bound)*)?
{
- type HigherRanked: ?Sized + LowerForLt<$lt, $($lifetimes,)* B, $($generic),*>;
+ type HigherRanked: ?Sized + LowerForLt<$lt, $($lifetimes,)* B, $($generic,)* T = Self> + $($lifetimes +)*;
}
pub trait Trait<$($lifetimes,)* $($generic),*>:
@@ -175,23 +175,104 @@ macro_rules! bijective_higher_ranked_type {
$($ctx:lifetime),*
][
$($generic:ident),*
- ]: ($($type_class:tt)*)[$($type_class_lifetime:lifetime)*][$($type_class_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)*})?
- = for<$lt:lifetime> $for_lt_type:ty
- $(where {$($higher_bound:tt)*})?
} => {
- $vis struct $name<$($type_class_lifetime,)* $($generic),*>(core::marker::PhantomData<fn() -> ($(&$type_class_lifetime (),)* $($generic,)*)>);
-
- impl<$lt, $($ctx,)* $($generic),*> $($type_class)*::LowerForLt<$lt, $($type_class_lifetime,)* &$lt ($(&$type_class_lifetime (),)* $($generic,)*), $($type_class_generic),*> for $name<$($type_class_lifetime,)* $($generic),*>
- where $($($bound)*)? $($($higher_bound)*)?
+ $vis struct $name<
+ $($type_class_lifetime,)*
+ $($generic: ?Sized,)*
+ $($($forwarding_generic: ?Sized),*)?
+ >(
+ core::marker::PhantomData<fn() -> (
+ $(&$type_class_lifetime (),)*
+ $(*const $generic,)*
+ $($(*const $forwarding_generic,)*)?
+ )>
+ );
+
+ impl<
+ $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<
+ $($type_class_lifetime,)*
+ $($generic,)*
+ $($($forwarding_generic),*)?
+ >
+ where
+ $($(
+ $forwarding_generic: $type_class::LowerForLt<
+ $lt,
+ $($forward_lt,)*
+ &$lt (
+ $(&$forward_lt (),)*
+ $(*const $forward_generic,)*
+ )
+ $($forward_generic,)*
+ >,
+ )*)?
+ $($($bound)*)?
{
type T = $for_lt_type;
}
- impl<$lt, $($ctx,)* $($generic),*> $($type_class)*::RaiseForLt<$lt, $($type_class_lifetime,)* &$lt ($(&$type_class_lifetime (),)* $($generic,)*), $($type_class_generic),*> for $for_lt_type
- where $($($bound)*)? $($($higher_bound)*)?
+ impl<
+ $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)*)?
{
- type HigherRanked = $name<$($type_class_lifetime,)* $($generic),*>;
+ type HigherRanked = $name<
+ $($type_class_lifetime,)*
+ $($generic,)*
+ $($(
+ <$forwarding_generic as $type_class::RaiseForLt<
+ $lt,
+ $($forward_lt,)*
+ &$lt (
+ $(&$forward_lt (),)*
+ $(*const $forward_generic,)*
+ )
+ $($forward_generic,)*
+ >>::HigherRanked
+ ),*)?
+ >;
}
};
{
@@ -199,26 +280,55 @@ macro_rules! bijective_higher_ranked_type {
$($ctx:lifetime),*
][
$($generic:ident),*
- ]: ($($type_class:tt)*)[$($type_class_lifetime:lifetime)*][$($type_class_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)*})?
- = for<$lt:lifetime> $for_lt_type:ty
- $(where {$($higher_bound:tt)*})?
} => {
const _: () = {
- $vis struct __Name<$($type_class_lifetime,)* $($generic: ?Sized),*>(core::marker::PhantomData<fn() -> ($(&$type_class_lifetime (),)* $(*const $generic),*)>);
-
- impl<$lt, $($ctx,)* $($generic),*> $($type_class)*::LowerForLt<$lt, $($type_class_lifetime,)* &$lt ($(&$type_class_lifetime (),)* $(*const $generic),*), $($type_class_generic),*> for __Name<$($type_class_lifetime,)* $($generic),*>
- where $($($bound)*)? $($($higher_bound)*)?
- {
- type T = $for_lt_type;
- }
-
- impl<$lt, $($ctx,)* $($generic),*> $($type_class)*::RaiseForLt<$lt, $($type_class_lifetime,)* &$lt ($(&$type_class_lifetime (),)* $(*const $generic),*), $($type_class_generic),*> for $for_lt_type
- where $($($bound)*)? $($($higher_bound)*)?
- {
- type HigherRanked = __Name<$($type_class_lifetime,)* $($generic),*>;
+ $crate::hkt::bijective_higher_ranked_type! {
+ $vis 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)*})?
}
};
+ };
+ {
+ $vis:vis 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! {
+ $vis 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)*})?
+ }
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 22d1433..8a7e2fa 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -8,13 +8,13 @@
extern crate alloc;
pub mod any;
-// mod build;
+mod build;
pub mod effect;
pub mod hkt;
-// pub mod protocol;
+pub mod protocol;
pub mod symbol;
-// mod walk;
-// mod transform;
+mod transform;
+mod walk;
// pub use build::Build;
// pub use build::Builder;
@@ -24,12 +24,12 @@ pub mod symbol;
use core::ops::ControlFlow;
-// pub use build::*;
-// use effect::{Effect, Future};
+pub use build::*;
+use effect::{Effect, Future};
// use protocol::{visitor::tag::TagError, Visitor};
use symbol::Symbol;
-// pub use transform::*;
-// pub use walk::*;
+pub use transform::*;
+pub use walk::*;
// #[doc(hidden)]
pub mod macros;
@@ -66,6 +66,7 @@ pub const TAG_ENUM: Symbol = Symbol::new("Enum");
pub enum DefaultMode {}
+#[derive(Clone, Copy, PartialEq, Debug)]
#[must_use]
pub enum Flow {
/// Processing should continue as normal.
@@ -124,7 +125,7 @@ macro_rules! Walk {
fn walk_field<'a, E: $crate::effect::Effect<'ctx>>(
index: usize,
value: &'ctx Self::T,
- visitor: $crate::Visitor<'a, 'ctx>,
+ visitor: $crate::protocol::Visitor<'a, 'ctx>,
) -> $crate::effect::Future<'a, 'ctx, Result<$crate::Flow, Self::FieldError>, E> {
mod fields {
enum Fields {$($field),*}
@@ -162,48 +163,48 @@ pub struct Demo {
pub b: bool,
}
-// Walk! {
-// pub struct Demo {
-// a: bool,
-// b: bool,
-// }
-// }
+Walk! {
+ pub struct Demo {
+ a: bool,
+ b: bool,
+ }
+}
-// #[cfg(test)]
-// mod test {
-// use crate::effect::{BlockOn, Blocking, Spin};
-//
-// use super::*;
-// use macro_rules_attribute::derive;
-//
-// #[derive(Walk!)]
-// struct Demo {
-// a: bool,
-// b: bool,
-// other: Other,
-// }
-//
-// #[derive(Walk!)]
-// struct Other {
-// value: bool,
-// }
-//
-// #[test]
-// fn demo() {
-// let value = Demo {
-// a: true,
-// b: false,
-// other: Other { value: true },
-// };
-//
-// let walker = Walk::<DefaultMode, Blocking>::into_walker(&value);
-// let mut visitor = builders::debug::Visitor::<Blocking>::new();
-//
-// dbg!(Spin::block_on(Walker::<Blocking>::walk(
-// walker,
-// &mut visitor
-// )));
-//
-// todo!();
-// }
-// }
+#[cfg(test)]
+mod test {
+ use crate::effect::{BlockOn, Blocking, Spin};
+
+ use super::*;
+ use macro_rules_attribute::derive;
+
+ #[derive(Walk!)]
+ struct Demo {
+ a: bool,
+ b: bool,
+ other: Other,
+ }
+
+ #[derive(Walk!)]
+ struct Other {
+ value: bool,
+ }
+
+ #[test]
+ fn demo() {
+ let value = Demo {
+ a: true,
+ b: false,
+ other: Other { value: true },
+ };
+
+ let walker = Walk::<DefaultMode, Blocking>::into_walker(&value);
+ let mut visitor = builders::debug::Visitor::<Blocking>::new();
+
+ dbg!(Spin::block_on(Walker::<Blocking>::walk(
+ walker,
+ &mut visitor
+ )));
+
+ todo!();
+ }
+}
diff --git a/src/protocol/visitor/recoverable.rs b/src/protocol/visitor/recoverable.rs
index 3ed49d3..4e1b307 100644
--- a/src/protocol/visitor/recoverable.rs
+++ b/src/protocol/visitor/recoverable.rs
@@ -1,8 +1,9 @@
use crate::{
+ any::{MaybeSized, TypeName},
+ bijective_higher_ranked_type,
effect::{Effect, Future},
higher_ranked_type,
hkt::AnySend,
- nameable,
protocol::{walker::hint::HintMeta, Visitor},
Flow,
};
@@ -16,13 +17,21 @@ pub trait Recoverable<'ctx, E: Effect<'ctx>> {
) -> Future<'a, 'ctx, Flow, E>;
}
-pub type DynRecoverable<'a, 'ctx, E> = &'a mut (dyn Recoverable<'ctx, E> + Send + 'a);
-
-nameable! {
- pub struct Name['ctx, E] for<'a>;
+bijective_higher_ranked_type! {
+ pub type DynRecoverable['ctx][E]: MaybeSized['ctx][]
+ for<'a>
+ (dyn Recoverable<'ctx, E> + Send + 'a)
+ where {
+ E: Effect<'ctx>
+ }
+}
- impl [E] for DynRecoverable<'a, 'ctx, E> where {
- E: Effect<'ctx>,
+bijective_higher_ranked_type! {
+ pub type [][E]: TypeName[][]
+ for<'ctx>
+ (DynRecoverable<'ctx, E>)
+ where {
+ E: Effect<'ctx>
}
}
@@ -36,7 +45,7 @@ higher_ranked_type! {
pub type RecoverableKnownHkt['ctx]: (AnySend) = for<'lt> ()
}
-impl<'a, 'ctx: 'a, E: Effect<'ctx>> HintMeta<'ctx> for DynRecoverable<'a, 'ctx, E> {
+impl<'ctx, E: Effect<'ctx>> HintMeta<'ctx> for DynRecoverable<'ctx, E> {
type Known = RecoverableKnownHkt<'ctx>;
type Hint = ();
@@ -46,7 +55,7 @@ pub fn visit_recoverable<'a, 'ctx, E: Effect<'ctx>>(
visitor: Visitor<'a, 'ctx>,
scope: DynRecoverableScope<'a, 'ctx, E>,
) -> Future<'a, 'ctx, Status, E> {
- if let Some(object) = visitor.upcast_mut::<DynRecoverable<'_, 'ctx, E>>() {
+ if let Some(object) = visitor.upcast_mut::<DynRecoverable<'ctx, E>>() {
// Allow the visitor to give a hint if it wants.
E::map(object.visit(scope), |flow| match flow {
Flow::Continue => {
diff --git a/src/protocol/visitor/request_hint.rs b/src/protocol/visitor/request_hint.rs
index 516dffa..aa5f8ee 100644
--- a/src/protocol/visitor/request_hint.rs
+++ b/src/protocol/visitor/request_hint.rs
@@ -1,6 +1,7 @@
use crate::{
+ any::{MaybeSized, TypeName},
+ bijective_higher_ranked_type,
effect::{Effect, Future},
- nameable,
protocol::{Visitor, Walker},
Flow,
};
@@ -14,12 +15,21 @@ pub trait RequestHint<'ctx, E: Effect<'ctx>> {
fn request_hint<'a>(&'a mut self, walker: Walker<'a, 'ctx>) -> Future<'a, 'ctx, Flow, E>;
}
-pub type DynRequestHint<'a, 'ctx, E> = dyn RequestHint<'ctx, E> + Send + 'a;
+bijective_higher_ranked_type! {
+ pub type DynRequestHint['ctx][E]: MaybeSized['ctx][]
+ for<'a>
+ (dyn RequestHint<'ctx, E> + Send + 'a)
+ where {
+ E: Effect<'ctx>
+ }
+}
-nameable! {
- pub struct Name['ctx, E] for <'a>;
- impl [E] for DynRequestHint<'a, 'ctx, E> where {
- E: Effect<'ctx>,
+bijective_higher_ranked_type! {
+ pub type [][E]: TypeName[][]
+ for<'ctx>
+ (DynRequestHint<'ctx, E>)
+ where {
+ E: Effect<'ctx>
}
}
@@ -34,7 +44,7 @@ pub fn visit_request_hint<'a, 'ctx, E: Effect<'ctx>>(
visitor: Visitor<'a, 'ctx>,
walker: Walker<'a, 'ctx>,
) -> Future<'a, 'ctx, Flow, E> {
- if let Some(object) = visitor.upcast_mut::<DynRequestHint<'_, 'ctx, E>>() {
+ if let Some(object) = visitor.upcast_mut::<DynRequestHint<'ctx, 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 2f8735d..736a006 100644
--- a/src/protocol/visitor/sequence.rs
+++ b/src/protocol/visitor/sequence.rs
@@ -1,8 +1,9 @@
use crate::{
+ any::{MaybeSized, TypeName},
+ bijective_higher_ranked_type,
effect::{Effect, Future},
higher_ranked_type,
hkt::AnySend,
- nameable,
protocol::{walker::hint::HintMeta, Visitor},
Flow,
};
@@ -13,13 +14,21 @@ pub trait Sequence<'ctx, E: Effect<'ctx>> {
fn visit<'a>(&'a mut self, scope: DynSequenceScope<'a, 'ctx, E>) -> Future<'a, 'ctx, Flow, E>;
}
-pub type DynSequence<'a, 'ctx, E> = dyn Sequence<'ctx, E> + Send + 'a;
-
-nameable! {
- pub struct Name['ctx, E] for<'a>;
+bijective_higher_ranked_type! {
+ pub type DynSequence['ctx][E]: MaybeSized['ctx][]
+ for<'a>
+ (dyn Sequence<'ctx, E> + Send + 'a)
+ where {
+ E: Effect<'ctx>
+ }
+}
- impl [E] for DynSequence<'a, 'ctx, E> where {
- E: Effect<'ctx>,
+bijective_higher_ranked_type! {
+ pub type [][E]: TypeName[][]
+ for<'ctx>
+ (DynSequence<'ctx, E>)
+ where {
+ E: Effect<'ctx>
}
}
@@ -44,7 +53,7 @@ pub struct SequenceHint {
pub len: (usize, Option<usize>),
}
-impl<'a, 'ctx: 'a, E: Effect<'ctx>> HintMeta<'ctx> for DynSequence<'a, 'ctx, E> {
+impl<'ctx, E: Effect<'ctx>> HintMeta<'ctx> for DynSequence<'ctx, E> {
type Known = SequenceKnownHkt<'ctx>;
type Hint = SequenceHint;
@@ -54,7 +63,7 @@ pub fn visit_sequence<'a, 'ctx, E: Effect<'ctx>>(
visitor: Visitor<'a, 'ctx>,
scope: DynSequenceScope<'a, 'ctx, E>,
) -> Future<'a, 'ctx, Status, E> {
- if let Some(object) = visitor.upcast_mut::<DynSequence<'_, 'ctx, E>>() {
+ if let Some(object) = visitor.upcast_mut::<DynSequence<'ctx, E>>() {
// Allow the visitor to give a hint if it wants.
E::map(object.visit(scope), |flow| match flow {
Flow::Continue => {
diff --git a/src/protocol/visitor/tag.rs b/src/protocol/visitor/tag.rs
index 57cc4dc..b20454a 100644
--- a/src/protocol/visitor/tag.rs
+++ b/src/protocol/visitor/tag.rs
@@ -1,8 +1,9 @@
use crate::{
+ any::{MaybeSized, TypeName},
+ bijective_higher_ranked_type,
effect::{Effect, Future},
higher_ranked_type,
hkt::AnySend,
- nameable,
protocol::{walker::hint::HintMeta, Visitor},
symbol::Symbol,
DynWalker, DynWalkerAdapter, DynWalkerError, Flow, WalkerTypes,
@@ -46,14 +47,23 @@ pub trait Tag<'ctx, K: TagKind, E: Effect<'ctx>> {
) -> Future<'a, 'ctx, K::Flow, E>;
}
-pub type DynTag<'a, 'ctx, K, E> = dyn Tag<'ctx, K, E> + Send + 'a;
-
-nameable! {
- pub struct Name['ctx, K, E] for<'a>;
-
- impl [K, E] for DynTag<'a, 'ctx, K, E> where {
+bijective_higher_ranked_type! {
+ pub type DynTag['ctx][K, E]: MaybeSized['ctx][]
+ for<'a>
+ (dyn Tag<'ctx, K, E> + Send + 'a)
+ where {
+ E: Effect<'ctx>,
K: TagKind,
+ }
+}
+
+bijective_higher_ranked_type! {
+ pub type [][K, E]: TypeName[][]
+ for<'ctx>
+ (DynTag<'ctx, K, E>)
+ where {
E: Effect<'ctx>,
+ K: TagKind,
}
}
@@ -69,7 +79,7 @@ pub struct TagHint<K> {
pub kind: K,
}
-impl<'a, 'ctx: 'a, K, E> HintMeta<'ctx> for DynTag<'a, 'ctx, K, E> {
+impl<'ctx, K, E> HintMeta<'ctx> for DynTag<'ctx, K, E> {
type Known = TagKnownHkt<'ctx>;
type Hint = TagHint<K>;
@@ -133,7 +143,7 @@ where
W: WalkerTypes,
{
E::wrap(async move {
- let (flow, walker) = if let Some(object) = visitor.upcast_mut::<DynTag<'_, 'ctx, K, E>>() {
+ let (flow, walker) = if let Some(object) = visitor.upcast_mut::<DynTag<'ctx, K, E>>() {
// The visitor knows about this tag.
// Wrap the walker to allow it to be passed to a dyn walker argument.
@@ -145,7 +155,7 @@ where
(flow.into(), walker)
} 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::<DynTag<'ctx, 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 1ed5682..ca5d046 100644
--- a/src/protocol/visitor/value.rs
+++ b/src/protocol/visitor/value.rs
@@ -3,21 +3,21 @@
//! In some sense, this is the most basic protocol.
use crate::{
- any::{TypeName, TypeNameable},
+ any::{MaybeSized, TypeName},
+ bijective_higher_ranked_type,
effect::{Effect, Future},
higher_ranked_type,
hkt::AnySend,
- nameable,
protocol::{walker::hint::HintMeta, Visitor},
Flow,
};
-use super::Status;
+use super::{recoverable::Recoverable, Status};
/// Trait object for the [`Value`] protocol.
///
/// Types implementing the [`Value`] protocol will implement this trait.
-pub trait Value<'ctx, T, E: Effect<'ctx>> {
+pub trait Value<'ctx, T: MaybeSized::Trait<'ctx>, E: Effect<'ctx>> {
/// Visit a value of type `T`.
///
/// Use this to give a value to a visitor. Its expected that a walker
@@ -27,22 +27,27 @@ pub trait Value<'ctx, 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>(&'a mut self, value: T) -> Future<'a, 'ctx, Flow, E>;
+ fn visit<'a>(&'a mut self, value: MaybeSized::T<'a, 'ctx, T>) -> Future<'a, 'ctx, Flow, E>;
}
-pub type DynValue<'a, 'ctx, T, E> = dyn Value<'ctx, T, E> + Send + 'a;
-
-nameable! {
- pub struct Name['ctx, T, E] for<'a>;
-
- impl [T::Name, E] for DynValue<'a, 'ctx, T, E> where {
- T: TypeNameable<'ctx> + ?Sized,
+bijective_higher_ranked_type! {
+ pub type DynValue['ctx][T, E][]: MaybeSized['ctx][]
+ for<'a>
+ (dyn Value<'ctx, T, E> + Send + 'a)
+ where {
E: Effect<'ctx>,
+ T: ?Sized + MaybeSized::Trait<'ctx> + 'ctx
}
+}
- impl [T, E] where DynValue<'a, 'ctx, T::Nameable, E> {
- T: TypeName<'ctx> + ?Sized,
+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<'ctx>,
+ T: ?Sized,
}
}
@@ -51,17 +56,22 @@ higher_ranked_type! {
}
// This enrolls the Value protocol into the walker hint system.
-impl<'a, 'ctx: 'a, T, E: Effect<'ctx>> HintMeta<'ctx> for DynValue<'a, 'ctx, T, E> {
+impl<'a, 'ctx: 'a, T, E: Effect<'ctx>> HintMeta<'ctx> for DynValue<'ctx, T, E> {
type Known = ValueKnownHkt<'ctx>;
type Hint = ();
}
-pub fn visit_value<'a, 'ctx, T: TypeNameable<'ctx>, E: Effect<'ctx>>(
+pub fn visit_value<'a, 'ctx, T: MaybeSized::Member<'a, 'ctx> + 'ctx, E: Effect<'ctx>>(
visitor: Visitor<'a, 'ctx>,
value: T,
-) -> Future<'a, 'ctx, Status, E> {
- if let Some(object) = visitor.upcast_mut::<DynValue<'_, 'ctx, T, E>>() {
+) -> Future<'a, 'ctx, Status, E>
+where
+ MaybeSized::HigherRanked<'a, 'ctx, T>: TypeName::Member<'ctx> + Sized,
+{
+ if let Some(object) =
+ visitor.upcast_mut::<DynValue<'ctx, MaybeSized::HigherRanked<'a, 'ctx, T>, E>>()
+ {
// Allow the visitor to give a hint if it wants.
E::map(object.visit(value), |flow| match flow {
Flow::Continue => {
@@ -83,11 +93,14 @@ pub fn visit_value<'a, 'ctx, T: TypeNameable<'ctx>, E: Effect<'ctx>>(
#[cfg(test)]
mod test {
- use core::{marker::PhantomData, ops::ControlFlow};
+ use core::marker::PhantomData;
use crate::{
any::{
- static_wrapper::{BorrowedMutStatic, BorrowedStatic, OwnedStatic},
+ static_wrapper::{
+ BorrowedMutStatic, BorrowedStatic, DynBorrowedMutStatic, DynBorrowedStatic,
+ DynOwnedStatic, OwnedStatic,
+ },
AnyTrait,
},
any_trait,
@@ -100,7 +113,7 @@ mod test {
fn visit() {
struct Visitor<E>(Option<i32>, PhantomData<fn() -> E>);
- impl<'ctx, E> Value<'ctx, OwnedStatic<i32>, E> for Visitor<E>
+ impl<'ctx, E> Value<'ctx, DynOwnedStatic<'ctx, i32>, E> for Visitor<E>
where
E: Effect<'ctx>,
{
@@ -115,7 +128,7 @@ mod test {
}
}
- impl<'ctx, E> Value<'ctx, BorrowedStatic<'ctx, i32>, E> for Visitor<E>
+ impl<'ctx, E> Value<'ctx, DynBorrowedStatic<'ctx, i32>, E> for Visitor<E>
where
E: Effect<'ctx>,
{
@@ -131,9 +144,9 @@ mod test {
}
any_trait! {
- impl['a, 'ctx, E] Visitor<E> = [
- DynValue<'a, 'ctx, OwnedStatic<i32>, E>,
- DynValue<'a, 'ctx, BorrowedStatic<'ctx, i32>, E>,
+ impl['ctx, E] Visitor<E> = [
+ DynValue<'ctx, DynOwnedStatic<'ctx, i32>, E>,
+ DynValue<'ctx, DynBorrowedStatic<'ctx, i32>, E>,
] where E: Effect<'ctx>,
}
@@ -141,7 +154,7 @@ mod test {
let object: &mut (dyn AnyTrait<'_> + Send) = &mut v;
Spin::block_on(
object
- .upcast_mut::<DynValue<'_, '_, OwnedStatic<i32>, Blocking>>()
+ .upcast_mut::<DynValue<'_, DynOwnedStatic<'_, i32>, Blocking>>()
.unwrap()
.visit(OwnedStatic(42)),
);
@@ -151,7 +164,7 @@ mod test {
let object: &mut (dyn AnyTrait<'_> + Send) = &mut v;
Spin::block_on(
object
- .upcast_mut::<DynValue<'_, '_, BorrowedStatic<'_, i32>, Blocking>>()
+ .upcast_mut::<DynValue<'_, DynBorrowedStatic<'_, i32>, Blocking>>()
.unwrap()
.visit(BorrowedStatic(&101)),
);
@@ -163,7 +176,7 @@ mod test {
fn visit_borrowed() {
struct Visitor<'ctx, E>(Option<&'ctx mut String>, PhantomData<fn() -> E>);
- impl<'ctx, E> Value<'ctx, BorrowedMutStatic<'ctx, String>, E> for Visitor<'ctx, E>
+ impl<'ctx, E> Value<'ctx, DynBorrowedMutStatic<'ctx, String>, E> for Visitor<'ctx, E>
where
E: Effect<'ctx>,
{
@@ -180,8 +193,8 @@ mod test {
}
any_trait! {
- impl['a, 'ctx, E] Visitor<'ctx, E> = [
- DynValue<'a, 'ctx, BorrowedMutStatic<'ctx, String>, E>,
+ impl['ctx, E] Visitor<'ctx, E> = [
+ DynValue<'ctx, DynBorrowedMutStatic<'ctx, String>, E>,
] where E: Effect<'ctx>
}
@@ -191,7 +204,7 @@ mod test {
let object: &mut (dyn AnyTrait<'_> + Send) = &mut v;
Spin::block_on(
object
- .upcast_mut::<DynValue<'_, '_, _, Blocking>>()
+ .upcast_mut::<DynValue<'_, DynBorrowedMutStatic<'_, _>, Blocking>>()
.unwrap()
.visit(BorrowedMutStatic(&mut y)),
);
@@ -204,7 +217,7 @@ mod test {
fn visit_borrowed_unsized() {
struct Visitor<'ctx, E>(Option<&'ctx str>, PhantomData<fn() -> E>);
- impl<'ctx, E> Value<'ctx, BorrowedStatic<'ctx, str>, E> for Visitor<'ctx, E>
+ impl<'ctx, E> Value<'ctx, DynBorrowedStatic<'ctx, str>, E> for Visitor<'ctx, E>
where
E: Effect<'ctx>,
{
@@ -220,8 +233,8 @@ mod test {
}
any_trait! {
- impl['a, 'ctx, E] Visitor<'ctx, E> = [
- DynValue<'a, 'ctx, BorrowedStatic<'ctx, str>, E>,
+ impl['ctx, E] Visitor<'ctx, E> = [
+ DynValue<'ctx, DynBorrowedStatic<'ctx, str>, E>,
] where E: Effect<'ctx>
}
@@ -231,7 +244,7 @@ mod test {
let object: &mut (dyn AnyTrait<'_> + Send) = &mut v;
Spin::block_on(
object
- .upcast_mut::<DynValue<'_, '_, BorrowedStatic<'_, str>, Blocking>>()
+ .upcast_mut::<DynValue<'_, DynBorrowedStatic<'_, str>, Blocking>>()
.unwrap()
.visit(BorrowedStatic(&y)),
);
diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs
index 1ec93b4..85184de 100644
--- a/src/protocol/walker/hint.rs
+++ b/src/protocol/walker/hint.rs
@@ -4,13 +4,11 @@
//! this module gives a protocol by which a visitor can give a hint
//! to the walker about what it is expecting.
-use core::ops::ControlFlow;
-
use crate::{
- any::{TypeName, TypeNameable},
+ any::{MaybeSized, TypeName},
+ bijective_higher_ranked_type,
effect::{Effect, Future},
hkt::AnySend,
- nameable,
protocol::Visitor,
Flow,
};
@@ -32,45 +30,47 @@ pub trait HintMeta<'ctx> {
pub type Known<'a, 'ctx, Protocol> = AnySend::T<'a, 'ctx, <Protocol as HintMeta<'ctx>>::Known>;
/// Object implementing the [`Hint`] protocol.
-pub trait Hint<'a, 'ctx: 'a, Protocol: ?Sized + HintMeta<'ctx>, E: Effect<'ctx>> {
+pub trait Hint<'ctx, Protocol: ?Sized + HintMeta<'ctx>, E: Effect<'ctx>> {
/// Hint to the walker to use the `P` protocol.
///
/// This should only be called once per [`RequestHint`].
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
hint: <Protocol as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E>;
/// Ask the walker for information about it's support of the protocol.
- fn known(
+ fn known<'a>(
&'a mut self,
hint: &'a <Protocol as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, Protocol>, ()>, E>;
}
-pub type DynHint<'a, 'ctx, Protocol, E> = dyn Hint<'a, 'ctx, Protocol, E> + Send + 'a;
-
-nameable! {
- pub struct Name['ctx, Protocol, E] for<'a>;
-
- impl [Protocol::Name, E] for DynHint<'a, 'ctx, Protocol, E> where {
- Protocol: TypeNameable<'ctx> + ?Sized,
+bijective_higher_ranked_type! {
+ pub type DynHint['ctx][Protocol, E]: MaybeSized['ctx][]
+ for<'a>
+ (dyn Hint<'ctx, Protocol, E> + Send + 'a)
+ where {
E: Effect<'ctx>,
+ Protocol: ?Sized + MaybeSized::Trait<'ctx> + 'ctx,
}
+}
- impl [Protocol, E] where DynHint<'a, 'ctx, Protocol::Nameable, E> {
- Protocol: TypeName<'ctx> + ?Sized,
+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<'ctx>,
+ Protocol: ?Sized,
}
}
#[cfg(test)]
mod test {
- use core::ops::ControlFlow;
-
use crate::{
- any::TypeNameable,
effect::{BlockOn, Blocking, Spin},
higher_ranked_type,
};
@@ -84,24 +84,27 @@ mod test {
#[derive(Debug)]
struct Y;
- nameable! {
- struct Name['a, 'ctx];
- impl for Y where {}
+ bijective_higher_ranked_type! {
+ type DynY['ctx][]: MaybeSized['ctx][] for<'a> (Y)
+ }
+
+ bijective_higher_ranked_type! {
+ type [][]: TypeName[][] for<'ctx> (DynY<'ctx>)
}
- impl<'a, 'ctx: 'a, E: Effect<'ctx>> Hint<'a, 'ctx, Y, E> for X<'ctx> {
- fn hint(
+ impl<'ctx, E: Effect<'ctx>> Hint<'ctx, DynY<'ctx>, E> for X<'ctx> {
+ fn hint<'a>(
&'a mut self,
_visitor: Visitor<'a, 'ctx>,
- _hint: <Y as HintMeta<'ctx>>::Hint,
+ _hint: <DynY<'ctx> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
todo!()
}
- fn known(
+ fn known<'a>(
&'a mut self,
- _hint: &'a <Y as HintMeta<'ctx>>::Hint,
- ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, Y>, ()>, E> {
+ _hint: &'a <DynY<'ctx> as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, DynY<'ctx>>, ()>, E> {
E::ready(Ok(&mut *self.0))
}
}
@@ -110,7 +113,7 @@ mod test {
type KnownHkt['ctx]: (AnySend) = for<'lt> &'lt mut i32
}
- impl<'ctx> HintMeta<'ctx> for Y {
+ impl<'ctx> HintMeta<'ctx> for DynY<'ctx> {
type Known = KnownHkt<'ctx>;
type Hint = ();
@@ -118,10 +121,10 @@ mod test {
let mut z = 42;
let mut x = X(&mut z);
- let y: &mut DynHint<'_, '_, Y, Blocking> = &mut x;
+ let y: &mut MaybeSized::T<'_, '_, DynHint<'_, DynY<'_>, Blocking>> = &mut x;
- fn id<'a, 'ctx, T: ?Sized + TypeNameable<'a, 'ctx>>(_x: &T) {}
- id(y);
+ fn id<'a, 'ctx, T: ?Sized + TypeName::Member<'ctx>>(_x: &MaybeSized::T<'a, 'ctx, T>) {}
+ id::<DynHint<'_, DynY<'_>, Blocking>>(y);
let x = Spin::block_on(y.known(&()));
match x {
diff --git a/src/walk/walkers/core/struct.rs b/src/walk/walkers/core/struct.rs
index a7d7e88..5ffb224 100644
--- a/src/walk/walkers/core/struct.rs
+++ b/src/walk/walkers/core/struct.rs
@@ -1,7 +1,7 @@
use core::{any::TypeId, marker::PhantomData};
use crate::{
- any::static_wrapper::BorrowedStatic,
+ any::static_wrapper::{BorrowedStatic, DynBorrowedStatic},
any_trait,
effect::{Effect, Future},
never::Never,
@@ -135,33 +135,32 @@ where
}
any_trait! {
- impl['a, 'ctx, T, I, M, E] StructWalker<'ctx, T, I, M, E> = [
- DynHint<'a, 'ctx, DynRecoverable<'a, 'ctx, E>, E>,
- DynHint<'a, 'ctx, DynSequence<'a, 'ctx, E>, E>,
- DynHint<'a, 'ctx, DynValue<'a, 'ctx, BorrowedStatic<'ctx, T>, E>, E>,
- DynHint<'a, 'ctx, DynTag<'a, 'ctx, TagDyn, E>, E>,
- DynHint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>, E>,
- DynHint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>, E>,
- DynHint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_MAP.to_int() }>, E>, E>,
- DynHint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>, E>,
- DynHint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>, E>,
+ 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, DynBorrowedStatic<'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>,
] where
E: Effect<'ctx>,
T: Sync + 'static,
I: StructTypeInfo<'ctx, M, T = T>
}
-impl<'a, 'ctx: 'a, T, I, M, E> Hint<'a, 'ctx, DynRecoverable<'a, 'ctx, E>, E>
- for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, DynRecoverable<'ctx, E>, E> for StructWalker<'ctx, T, I, M, E>
where
E: Effect<'ctx>,
I: StructTypeInfo<'ctx, M, T = T>,
T: Sync + 'static,
{
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynRecoverable<'a, 'ctx, E> as HintMeta<'ctx>>::Hint,
+ _hint: <DynRecoverable<'ctx, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
E::map(
visit_recoverable::<E>(visitor, self),
@@ -172,26 +171,25 @@ where
)
}
- fn known(
+ fn known<'a>(
&'a mut self,
- _hint: &'a <DynRecoverable<'a, 'ctx, E> as HintMeta<'ctx>>::Hint,
- ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, DynRecoverable<'a, 'ctx, E>>, ()>, E> {
+ _hint: &'a <DynRecoverable<'ctx, E> as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, DynRecoverable<'ctx, E>>, ()>, E> {
E::ready(Ok(()))
}
}
-impl<'a, 'ctx: 'a, T, I, M, E>
- Hint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect<'ctx>,
I: StructTypeInfo<'ctx, M>,
T: Sync + 'static,
{
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'a, 'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E, _>(
@@ -210,15 +208,15 @@ where
)
}
- fn known(
+ fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'a, 'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E> as HintMeta<
+ _hint: &'a <DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E> as HintMeta<
'ctx,
>>::Hint,
) -> Future<
'a,
'ctx,
- Result<Known<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>, ()>,
+ Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>, ()>,
E,
> {
E::ready(Ok(TagKnown {
@@ -227,18 +225,17 @@ where
}
}
-impl<'a, 'ctx: 'a, T, I, M, E>
- Hint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect<'ctx>,
I: StructTypeInfo<'ctx, M>,
T: Sync + 'static,
{
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_TYPE_NAME.to_int() }>, E, _>(
@@ -257,13 +254,13 @@ where
)
}
- fn known(
+ fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: &'a <DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<
'a,
'ctx,
- Result<Known<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>, ()>,
+ Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>, ()>,
E,
> {
E::ready(Ok(TagKnown {
@@ -272,18 +269,17 @@ where
}
}
-impl<'a, 'ctx: 'a, T, I, M, E>
- Hint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_MAP.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect<'ctx>,
I: StructTypeInfo<'ctx, M>,
T: Sync + 'static,
{
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'a, 'ctx, TagConst<{ TAG_MAP.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_MAP.to_int() }>, E, _>(TagConst, visitor, NoopWalker::new()),
@@ -298,13 +294,13 @@ where
)
}
- fn known(
+ fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'a, 'ctx, TagConst<{ TAG_MAP.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: &'a <DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<
'a,
'ctx,
- Result<Known<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_MAP.to_int() }>, E>>, ()>,
+ Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E>>, ()>,
E,
> {
E::ready(Ok(TagKnown {
@@ -313,18 +309,17 @@ where
}
}
-impl<'a, 'ctx: 'a, T, I, M, E>
- Hint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect<'ctx>,
I: StructTypeInfo<'ctx, M>,
T: Sync + 'static,
{
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'a, 'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_STRUCT.to_int() }>, E, _>(
@@ -343,13 +338,13 @@ where
)
}
- fn known(
+ fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'a, 'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: &'a <DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<
'a,
'ctx,
- Result<Known<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>>, ()>,
+ Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>>, ()>,
E,
> {
E::ready(Ok(TagKnown {
@@ -358,18 +353,17 @@ where
}
}
-impl<'a, 'ctx: 'a, T, I, M, E>
- Hint<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect<'ctx>,
I: StructTypeInfo<'ctx, M>,
T: Sync + 'static,
{
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: <DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
E::map(
visit_tag::<TagConst<{ TAG_TYPE_ID.to_int() }>, E, _>(
@@ -388,13 +382,13 @@ where
)
}
- fn known(
+ fn known<'a>(
&'a mut self,
- _hint: &'a <DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E> as HintMeta<'ctx>>::Hint,
+ _hint: &'a <DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E> as HintMeta<'ctx>>::Hint,
) -> Future<
'a,
'ctx,
- Result<Known<'a, 'ctx, DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>>, ()>,
+ Result<Known<'a, 'ctx, DynTag<'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>>, ()>,
E,
> {
E::ready(Ok(TagKnown {
@@ -403,57 +397,55 @@ where
}
}
-impl<'a, 'ctx: 'a, T, I, M, E> Hint<'a, 'ctx, DynTag<'a, 'ctx, TagDyn, E>, E>
- for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, DynTag<'ctx, TagDyn, E>, E> for StructWalker<'ctx, T, I, M, E>
where
E: Effect<'ctx>,
I: StructTypeInfo<'ctx, M>,
T: Sync + 'static,
{
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- hint: <DynTag<'a, 'ctx, TagDyn, E> as HintMeta<'ctx>>::Hint,
+ hint: <DynTag<'ctx, TagDyn, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
match hint.kind.0 {
crate::TAG_TYPE_ID => Hint::<
- 'a,
- 'ctx,
- DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_ID.to_int() }>, E>,
- E,
- >::hint(self, visitor, TagHint { kind: TagConst }),
- crate::TAG_STRUCT => Hint::<
- 'a,
'ctx,
- DynTag<'a, 'ctx, TagConst<{ TAG_STRUCT.to_int() }>, E>,
- E,
- >::hint(self, visitor, TagHint { kind: TagConst }),
- crate::TAG_MAP => Hint::<
- 'a,
- 'ctx,
- DynTag<'a, 'ctx, TagConst<{ TAG_MAP.to_int() }>, E>,
+ DynTag<'ctx, 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(
+ self,
+ visitor,
+ TagHint { kind: TagConst },
+ )
+ }
+ crate::TAG_MAP => {
+ Hint::<'ctx, DynTag<'ctx, TagConst<{ TAG_MAP.to_int() }>, E>, E>::hint(
+ self,
+ visitor,
+ TagHint { kind: TagConst },
+ )
+ }
crate::TAG_TYPE_NAME => Hint::<
- 'a,
'ctx,
- DynTag<'a, 'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>,
+ DynTag<'ctx, TagConst<{ TAG_TYPE_NAME.to_int() }>, E>,
E,
>::hint(self, visitor, TagHint { kind: TagConst }),
crate::TAG_FIELD_NAMES => Hint::<
- 'a,
'ctx,
- DynTag<'a, 'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>,
+ DynTag<'ctx, TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>,
E,
>::hint(self, visitor, TagHint { kind: TagConst }),
_ => E::ready(Flow::Continue),
}
}
- fn known(
+ fn known<'a>(
&'a mut self,
- hint: &'a <DynTag<'a, 'ctx, TagDyn, E> as HintMeta<'ctx>>::Hint,
- ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, DynTag<'a, 'ctx, TagDyn, E>>, ()>, E> {
+ hint: &'a <DynTag<'ctx, TagDyn, E> as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, DynTag<'ctx, TagDyn, E>>, ()>, E> {
E::ready(match hint.kind {
TagDyn(crate::TAG_TYPE_ID) | TagDyn(crate::TAG_STRUCT) => Ok(TagKnown {
kind_available: Some(true),
@@ -465,14 +457,14 @@ where
}
}
-impl<'a, 'ctx: 'a, T, I, M, E> Hint<'a, 'ctx, DynValue<'a, 'ctx, BorrowedStatic<'ctx, T>, E>, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, DynValue<'ctx, DynBorrowedStatic<'ctx, T>, E>, E>
for StructWalker<'ctx, T, I, M, E>
where
E: Effect<'ctx>,
I: StructTypeInfo<'ctx, M>,
T: Sync + 'static,
{
- fn hint(&'a mut self, visitor: Visitor<'a, 'ctx>, _hint: ()) -> Future<'a, 'ctx, Flow, E> {
+ fn hint<'a>(&'a mut self, visitor: Visitor<'a, 'ctx>, _hint: ()) -> Future<'a, 'ctx, Flow, E> {
E::map(
visit_value::<_, E>(visitor, BorrowedStatic(self.value)),
|status| match status {
@@ -482,22 +474,21 @@ where
)
}
- fn known(&'a mut self, _hint: &'a ()) -> Future<'a, 'ctx, Result<(), ()>, E> {
+ fn known<'a>(&'a mut self, _hint: &'a ()) -> Future<'a, 'ctx, Result<(), ()>, E> {
E::ready(Ok(()))
}
}
-impl<'a, 'ctx: 'a, T, I, M, E> Hint<'a, 'ctx, DynSequence<'a, 'ctx, E>, E>
- for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, T, I, M, E> Hint<'ctx, DynSequence<'ctx, E>, E> for StructWalker<'ctx, T, I, M, E>
where
E: Effect<'ctx>,
I: StructTypeInfo<'ctx, M, T = T>,
T: Sync,
{
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
- _hint: <DynSequence<'a, 'ctx, E> as HintMeta<'ctx>>::Hint,
+ _hint: <DynSequence<'ctx, E> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
E::map(visit_sequence::<E>(visitor, self), |status| match status {
Status::Skipped(_) => Flow::Continue,
@@ -505,10 +496,10 @@ where
})
}
- fn known(
+ fn known<'a>(
&'a mut self,
- _hint: &'a <DynSequence<'a, 'ctx, E> as HintMeta<'ctx>>::Hint,
- ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, DynSequence<'a, 'ctx, E>>, ()>, E> {
+ _hint: &'a <DynSequence<'ctx, E> as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, DynSequence<'ctx, 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 9362f6c..22e117b 100644
--- a/src/walk/walkers/core/tag.rs
+++ b/src/walk/walkers/core/tag.rs
@@ -1,7 +1,7 @@
use core::{any::TypeId, marker::PhantomData};
use crate::{
- any::static_wrapper::OwnedStatic,
+ any::static_wrapper::{DynOwnedStatic, OwnedStatic},
any_trait,
effect::{Effect, Future},
never::Never,
@@ -68,7 +68,7 @@ where
_ => return Ok(()),
}
- if let Some(object) = visitor.upcast_mut::<DynSequence<'_, 'ctx, E>>() {
+ if let Some(object) = visitor.upcast_mut::<DynSequence<'ctx, E>>() {
// Visit with the name. Ignore the flow because we return a result not a flow.
let _ = object.visit(&mut self).await;
}