Diffstat (limited to 'src/build/builders/core/struct.rs')
-rw-r--r--src/build/builders/core/struct.rs161
1 files changed, 85 insertions, 76 deletions
diff --git a/src/build/builders/core/struct.rs b/src/build/builders/core/struct.rs
index feada5d..fa22457 100644
--- a/src/build/builders/core/struct.rs
+++ b/src/build/builders/core/struct.rs
@@ -1,7 +1,7 @@
use crate::{
any::{OwnedStatic, TempBorrowedStatic, TempBorrowedStaticHrt, TypeName},
any_trait,
- effect::{Effect, Future},
+ effect::{Effect, ObjSafe, Adapters},
hkt::Marker,
protocol::{
visitor::{
@@ -40,9 +40,9 @@ pub trait StructTypeInfo<'ctx, M, E: Effect>: 'static {
type T: Send + Sync;
- fn new_builders<'a>(seed: Self::Seed) -> Future<'a, Self::Builders, E>;
+ fn new_builders<'a>(seed: Self::Seed) -> ObjSafe<'a, Self::Builders, E>;
- fn from_builders<'a>(builders: Self::Builders) -> Future<'a, Result<Self::T, Self::Error>, E>;
+ fn from_builders<'a>(builders: Self::Builders) -> ObjSafe<'a, Result<Self::T, Self::Error>, E>;
fn as_visitor<'a>(
marker: Self::FieldMarker,
@@ -83,30 +83,30 @@ where
I: StructTypeInfo<'ctx, M, E>,
E: Effect,
{
- fn from_seed<'a>(seed: Self::Seed) -> Future<'a, Self, E>
+ fn from_seed<'a>(seed: Self::Seed) -> ObjSafe<'a, Self, E>
where
Self: 'a,
{
- E::wrap(async {
+ I::new_builders(seed).map(|builders| {
Self {
- builders: I::new_builders(seed).await,
+ builders,
// Start in tuple mode until a struct or map tag is visited.
mode: StructMode::Tuple,
_generics: Default::default(),
}
- })
+ }).into()
}
- fn build<'a>(self) -> Future<'a, Result<Self::Value, Self::Error>, E>
+ fn build<'a>(self) -> ObjSafe<'a, Result<Self::Value, Self::Error>, E>
where
Self: 'a,
{
- E::wrap(async {
- match I::from_builders(self.builders).await {
+ I::from_builders(self.builders).map(|builders| {
+ match builders {
Ok(value) => Ok(value),
Err(err) => Err(StructError { error: err }),
}
- })
+ }).into()
}
fn as_visitor(&mut self) -> DynVisitor<'_, 'ctx> {
@@ -128,21 +128,24 @@ where
I: StructTypeInfo<'ctx, M, E>,
E: Effect,
{
+ #[inline(always)]
fn visit<'a>(
&'a mut self,
_kind: tags::Map,
walker: DynWalkerObjSafe<'a, 'ctx, E>,
- ) -> Future<'a, VisitResult<DynWalkerObjSafe<'a, 'ctx, E>>, E> {
+ ) -> ObjSafe<'a, VisitResult<DynWalkerObjSafe<'a, 'ctx, E>>, E> {
// This signals to go into map mode for the sequence.
self.mode = StructMode::Map;
- E::wrap(async {
+ E::with(NoopVisitor::new(), |noop| {
walker
- .walk(DynVisitor(&mut NoopVisitor::new()))
- .await
- .to_continue()
+ .walk(DynVisitor(noop))
+ .map(|x| {
+ x.to_continue()
+ .into()
+ })
.into()
- })
+ }).into()
}
}
@@ -156,45 +159,46 @@ where
fn visit<'a>(
&'a mut self,
scope: DynSequenceScope<'a, 'ctx, E>,
- ) -> Future<'a, VisitResult<DynSequenceScope<'a, 'ctx, E>>, E> {
- match self.mode {
- StructMode::Tuple => E::wrap(async {
- let mut index = 0;
-
- // For each index based marker.
- while let Some(marker) = I::marker_from_index(index) {
- // Select the visitor for this field.
- let visitor = I::as_visitor(marker, &mut self.builders);
-
- // Get the next value in the sequence.
- match scope.next(visitor).await {
- Flow::Continue => {}
- Flow::Err => return VisitResult::Control(Flow::Err),
- Flow::Done => break,
- }
-
- // Move to the next field.
- index += 1;
- }
-
- VisitResult::Control(Flow::Done)
- }),
- StructMode::Map => E::wrap(async {
- loop {
- let mut visitor = FieldVisitor::<I, M, E> {
- builders: &mut self.builders,
- marker: None,
- _marker: Default::default(),
- };
-
- match scope.next(DynVisitor(&mut visitor)).await {
- Flow::Continue => {}
- Flow::Err => return VisitResult::Control(Flow::Err),
- Flow::Done => return VisitResult::Control(Flow::Done),
- }
- }
- }),
- }
+ ) -> ObjSafe<'a, VisitResult<DynSequenceScope<'a, 'ctx, E>>, E> {
+ todo!()
+ // match self.mode {
+ // StructMode::Tuple => E::wrap(async {
+ // let mut index = 0;
+ //
+ // // For each index based marker.
+ // while let Some(marker) = I::marker_from_index(index) {
+ // // Select the visitor for this field.
+ // let visitor = I::as_visitor(marker, &mut self.builders);
+ //
+ // // Get the next value in the sequence.
+ // match scope.next(visitor).await {
+ // Flow::Continue => {}
+ // Flow::Err => return VisitResult::Control(Flow::Err),
+ // Flow::Done => break,
+ // }
+ //
+ // // Move to the next field.
+ // index += 1;
+ // }
+ //
+ // VisitResult::Control(Flow::Done)
+ // }),
+ // StructMode::Map => E::wrap(async {
+ // loop {
+ // let mut visitor = FieldVisitor::<I, M, E> {
+ // builders: &mut self.builders,
+ // marker: None,
+ // _marker: Default::default(),
+ // };
+ //
+ // match scope.next(DynVisitor(&mut visitor)).await {
+ // Flow::Continue => {}
+ // Flow::Err => return VisitResult::Control(Flow::Err),
+ // Flow::Done => return VisitResult::Control(Flow::Done),
+ // }
+ // }
+ // }),
+ // }
}
}
@@ -226,24 +230,26 @@ where
E: Effect,
I: StructTypeInfo<'ctx, M, E>,
{
+ #[inline(always)]
fn visit<'a>(
&'a mut self,
_key: tags::Key,
walker: DynWalkerObjSafe<'a, 'ctx, E>,
- ) -> Future<'a, VisitResult<DynWalkerObjSafe<'a, 'ctx, E>>, E> {
- E::wrap(async {
- let mut visitor = NameVisitor::<I, M, E> {
- field_marker: None,
- _marker: Default::default(),
- };
-
- let flow = walker.walk(DynVisitor(&mut visitor)).await;
-
- self.marker = visitor.field_marker;
-
- // We are expecting the value of the field to be given next.
- flow.to_continue().into()
- })
+ ) -> ObjSafe<'a, VisitResult<DynWalkerObjSafe<'a, 'ctx, E>>, E> {
+ todo!()
+ // E::wrap(async {
+ // let mut visitor = NameVisitor::<I, M, E> {
+ // field_marker: None,
+ // _marker: Default::default(),
+ // };
+ //
+ // let flow = walker.walk(DynVisitor(&mut visitor)).await;
+ //
+ // self.marker = visitor.field_marker;
+ //
+ // // We are expecting the value of the field to be given next.
+ // flow.to_continue().into()
+ // })
}
}
@@ -267,17 +273,18 @@ where
E: Effect,
I: StructTypeInfo<'ctx, M, E>,
{
+ #[inline(always)]
fn visit<'a>(
&'a mut self,
OwnedStatic(index): TypeName::T<'a, 'ctx, OwnedStatic<usize>>,
- ) -> Future<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<usize>>>, E>
+ ) -> ObjSafe<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<usize>>>, E>
where
TypeName::T<'a, 'ctx, OwnedStatic<usize>>: Send + Sized,
'ctx: 'a,
{
self.field_marker = I::marker_from_index(index);
- E::ready(VisitResult::Control(Flow::Done))
+ E::ready(VisitResult::Control(Flow::Done)).into()
}
}
@@ -286,17 +293,18 @@ where
E: Effect,
I: StructTypeInfo<'ctx, M, E>,
{
+ #[inline(always)]
fn visit<'a>(
&'a mut self,
TempBorrowedStatic(name): TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>>,
- ) -> Future<'a, VisitResult<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>>>, E>
+ ) -> ObjSafe<'a, VisitResult<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>>>, E>
where
TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>>: Send + Sized,
'ctx: 'a,
{
self.field_marker = I::marker_from_name(name);
- E::ready(VisitResult::Control(Flow::Done))
+ E::ready(VisitResult::Control(Flow::Done)).into()
}
}
@@ -305,16 +313,17 @@ where
E: Effect,
I: StructTypeInfo<'ctx, M, E>,
{
+ #[inline(always)]
fn visit<'a>(
&'a mut self,
OwnedStatic(name): TypeName::T<'a, 'ctx, OwnedStatic<&'static str>>,
- ) -> Future<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<&'static str>>>, E>
+ ) -> ObjSafe<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<&'static str>>>, E>
where
TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>>: Send + Sized,
'ctx: 'a,
{
self.field_marker = I::marker_from_name(name);
- E::ready(VisitResult::Control(Flow::Done))
+ E::ready(VisitResult::Control(Flow::Done)).into()
}
}