Diffstat (limited to 'src/walk/walkers/core/struct.rs')
-rw-r--r--src/walk/walkers/core/struct.rs115
1 files changed, 58 insertions, 57 deletions
diff --git a/src/walk/walkers/core/struct.rs b/src/walk/walkers/core/struct.rs
index 2cb4c14..9e67382 100644
--- a/src/walk/walkers/core/struct.rs
+++ b/src/walk/walkers/core/struct.rs
@@ -1,7 +1,7 @@
use core::any::TypeId;
use crate::{
- any::{BorrowedStatic, BorrowedStaticHrt},
+ any::{AnyTrait, BorrowedStatic, BorrowedStaticHrt},
any_trait,
effect::{Effect, Future},
hkt::Marker,
@@ -22,12 +22,16 @@ use crate::{
use super::{noop::NoopWalker, tag::StaticSliceWalker, value::ValueWalker};
+pub enum StaticType {}
+pub enum NamedType {}
+pub enum LifetimeType {}
+
/// Walker for a borrow of a struct.
///
/// This walker implements the struct flow. The struct cannot contain lifetimes.
-pub struct StructWalker<'ctx, T, I: StructTypeInfo<'ctx, M>, M, E> {
+pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, S = S>, S, M, E> {
/// Struct value to walk.
- value: &'ctx T,
+ value: &'ctx I::T,
/// Index of the current field to walk.
index: usize,
@@ -37,7 +41,7 @@ pub struct StructWalker<'ctx, T, I: StructTypeInfo<'ctx, M>, M, E> {
/// The visitor tracks it's own errors.
error: Option<StructWalkErrorKind<I::FieldError>>,
- _generics: Marker<(I, M, E)>,
+ _generics: Marker<E>,
}
/// Type info about a struct needed by [`StructWalker`].
@@ -51,6 +55,8 @@ pub trait StructTypeInfo<'ctx, M>: 'static {
/// The walking errors for the fields.
type FieldError: Send + Sync;
+ type S: 'static;
+
/// The struct being described.
type T: Send + Sync;
@@ -86,12 +92,12 @@ pub struct StructWalkError<T> {
kind: StructWalkErrorKind<T>,
}
-impl<'ctx, T, I, M, E> StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, M, E> StructWalker<'ctx, I, S, M, E>
where
- I: StructTypeInfo<'ctx, M>,
+ I: StructTypeInfo<'ctx, M, S = S>,
{
/// Create walker from a borrow of a struct.
- pub fn new(value: &'ctx T) -> Self {
+ pub fn new(value: &'ctx I::T) -> Self {
Self {
value,
index: 0,
@@ -101,19 +107,19 @@ where
}
}
-impl<'ctx, T, I, M, E> WalkerTypes for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, M, E> WalkerTypes for StructWalker<'ctx, I, S, M, E>
where
- I: StructTypeInfo<'ctx, M>,
+ I: StructTypeInfo<'ctx, M, S = S>,
{
type Error = StructWalkError<I::FieldError>;
type Output = ();
}
-impl<'ctx, T, I, E, M> crate::Walker<'ctx, E> for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, E, M> crate::Walker<'ctx, E> for StructWalker<'ctx, I, S, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M, T = T>,
- T: Send + Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = S>,
+ Self: AnyTrait<'ctx> + RecoverableScope<'ctx, E>,
{
fn walk<'a>(
mut self,
@@ -136,10 +142,10 @@ where
}
any_trait! {
- impl['ctx, T, I, M, E] StructWalker<'ctx, T, I, M, E> = [
+ impl['ctx, I, M, E] StructWalker<'ctx, I, StaticType, M, E> = [
HintProto<RecoverableProto<E>>,
HintProto<SequenceProto<E>>,
- HintProto<ValueProto<BorrowedStaticHrt<T>, E>>,
+ HintProto<ValueProto<BorrowedStaticHrt<I::T>, E>>,
HintProto<TagProto<TagDyn, E>>,
HintProto<TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>>,
HintProto<TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>>,
@@ -148,15 +154,15 @@ any_trait! {
HintProto<TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>,
] where
E: Effect,
- T: Send + Sync + 'static,
- I: StructTypeInfo<'ctx, M, T = T>
+ I: StructTypeInfo<'ctx, M, S = StaticType>,
+ I::T: 'static
}
-impl<'ctx, T, I, M, E> Hint<'ctx, RecoverableProto<E>> for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, M, E> Hint<'ctx, RecoverableProto<E>> for StructWalker<'ctx, I, S, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M, T = T>,
- T: Send + Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = S>,
+ Self: AnyTrait<'ctx> + RecoverableScope<'ctx, E>,
{
fn hint<'a>(
&'a mut self,
@@ -180,12 +186,11 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>
- for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>
+ for StructWalker<'ctx, I, S, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M>,
- T: Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = S>,
{
fn hint<'a>(
&'a mut self,
@@ -223,12 +228,11 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>
- for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>
+ for StructWalker<'ctx, I, S, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M>,
- T: Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = S>,
{
fn hint<'a>(
&'a mut self,
@@ -266,12 +270,11 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>>
- for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>>
+ for StructWalker<'ctx, I, S, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M>,
- T: Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = S>,
{
fn hint<'a>(
&'a mut self,
@@ -302,12 +305,11 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>>
- for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>>
+ for StructWalker<'ctx, I, S, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M>,
- T: Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = S>,
{
fn hint<'a>(
&'a mut self,
@@ -345,12 +347,12 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>>
- for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>>
+ for StructWalker<'ctx, I, StaticType, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M>,
- T: Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = StaticType>,
+ I::T: 'static,
{
fn hint<'a>(
&'a mut self,
@@ -361,7 +363,7 @@ where
visit_tag::<TagConst<{ TAG_TYPE_ID.to_int() }>, E, _>(
TagConst,
visitor,
- ValueWalker::new(TypeId::of::<T>()),
+ ValueWalker::new(TypeId::of::<I::T>()),
),
|status| match status {
Err(err) => {
@@ -388,11 +390,11 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, TagProto<TagDyn, E>> for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, M, E> Hint<'ctx, TagProto<TagDyn, E>> for StructWalker<'ctx, I, StaticType, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M>,
- T: Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = StaticType>,
+ I::T: 'static,
{
fn hint<'a>(
&'a mut self,
@@ -449,12 +451,12 @@ where
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, ValueProto<BorrowedStaticHrt<T>, E>>
- for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, M, E> Hint<'ctx, ValueProto<BorrowedStaticHrt<I::T>, E>>
+ for StructWalker<'ctx, I, StaticType, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M>,
- T: Send + Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = StaticType>,
+ I::T: 'static,
{
fn hint<'a>(&'a mut self, visitor: DynVisitor<'a, 'ctx>, _hint: ()) -> Future<'a, Flow, E> {
E::map(
@@ -469,16 +471,15 @@ where
fn known<'a>(
&'a mut self,
_hint: &'a (),
- ) -> Future<'a, Result<ValueKnown<'a, BorrowedStatic<'ctx, T>>, ()>, E> {
+ ) -> Future<'a, Result<ValueKnown<'a, BorrowedStatic<'ctx, I::T>>, ()>, E> {
E::ready(Ok(ValueKnown { preview: None }))
}
}
-impl<'ctx, T, I, M, E> Hint<'ctx, SequenceProto<E>> for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, M, E> Hint<'ctx, SequenceProto<E>> for StructWalker<'ctx, I, S, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M, T = T>,
- T: Sync,
+ I: StructTypeInfo<'ctx, M, S = S>,
{
fn hint<'a>(
&'a mut self,
@@ -503,10 +504,10 @@ where
}
}
-impl<'ctx, T, I, M, E> SequenceScope<'ctx, E> for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, S, M, E> SequenceScope<'ctx, E> for StructWalker<'ctx, I, S, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M, T = T>,
+ I: StructTypeInfo<'ctx, M, S = S>,
{
fn size_hint(&mut self) -> Future<'_, (usize, Option<usize>), E> {
let len = I::FIELDS.len();
@@ -536,11 +537,11 @@ where
}
}
-impl<'ctx, T, I, M, E> RecoverableScope<'ctx, E> for StructWalker<'ctx, T, I, M, E>
+impl<'ctx, I, M, E> RecoverableScope<'ctx, E> for StructWalker<'ctx, I, StaticType, M, E>
where
E: Effect,
- I: StructTypeInfo<'ctx, M, T = T>,
- T: Send + Sync + 'static,
+ I: StructTypeInfo<'ctx, M, S = StaticType>,
+ I::T: 'static,
{
fn new_walk<'a>(&'a mut self, mut visitor: DynVisitor<'a, 'ctx>) -> Future<'a, Status, E> {
// Reset the errors to default state.
@@ -574,7 +575,7 @@ where
match visit_tag::<TagConst<{ TAG_TYPE_ID.to_int() }>, E, _>(
TagConst,
visitor.cast(),
- ValueWalker::new(TypeId::of::<T>()),
+ ValueWalker::new(TypeId::of::<I::T>()),
)
.await
{