Diffstat (limited to 'src/walk/walkers/serde/deserializer.rs')
-rw-r--r--src/walk/walkers/serde/deserializer.rs92
1 files changed, 49 insertions, 43 deletions
diff --git a/src/walk/walkers/serde/deserializer.rs b/src/walk/walkers/serde/deserializer.rs
index 115ace1..8818102 100644
--- a/src/walk/walkers/serde/deserializer.rs
+++ b/src/walk/walkers/serde/deserializer.rs
@@ -1,4 +1,10 @@
-use effectful::{effective::NativeEffective, environment::{DynBind, Environment, NativeForm, EnvConfig}, SendSync, effective::Effective, bound::{No, Dynamic}};
+use effectful::{
+ bound::{Dynamic, No},
+ effective::Effective,
+ effective::NativeEffective,
+ environment::{DynBind, EnvConfig, Environment, NativeForm},
+ SendSync,
+};
use serde::{de::MapAccess, Deserializer};
use crate::{
@@ -7,7 +13,8 @@ use crate::{
hkt::Marker,
protocol::{
visitor::{
- request_hint, tags, visit_sequence, visit_value, EffectiveVisitExt as _, SequenceScope, TagConst, TagKnown, TagProto, ValueKnown, ValueProto, VisitResult
+ request_hint, tags, visit_sequence, visit_value, EffectiveVisitExt as _, SequenceScope,
+ TagConst, TagKnown, TagProto, ValueKnown, ValueProto, VisitResult,
},
walker::hint::{DynVisitorWith, Hint, HintMeta, HintProto, MetaHint, MetaKnown},
DynVisitor, DynWalker,
@@ -106,25 +113,25 @@ where
{
E::value((self, visitor))
.update((), |_, (this, visitor)| {
- // Serde deserializers usually prefer that a hint method is called rather than _any.
- // As such we need to ask the visitor for a hint first.
- request_hint::<E>(visitor.cast(), DynWalker(this))
- .map((), |_, x| VisitResult::unit_skipped(x))
+ // Serde deserializers usually prefer that a hint method is called rather than _any.
+ // As such we need to ask the visitor for a hint first.
+ request_hint::<E>(visitor.cast(), DynWalker(this))
+ .map((), |_, x| VisitResult::unit_skipped(x))
+ .cast()
+ })
+ .if_not_finished((), |_, (this, visitor)| {
+ this.call_deserialize(|deserializer| {
+ deserializer.deserialize_any(Visitor::<T, E>::new(visitor.cast(), "any"))
+ })
.cast()
- })
- .if_not_finished((), |_, (this, visitor)| {
- this.call_deserialize(|deserializer| {
- deserializer.deserialize_any(Visitor::<T, E>::new(visitor.cast(), "any"))
+ })
+ .map((), |_, ((this, _), _)| match this.inner {
+ Inner::Temp => todo!(),
+ Inner::Init(_) => todo!(),
+ Inner::Error(err) => Err(err),
+ Inner::Done => Ok(()),
})
.cast()
- })
- .map((), |_, ((this, _), _)| match this.inner {
- Inner::Temp => todo!(),
- Inner::Init(_) => todo!(),
- Inner::Error(err) => Err(err),
- Inner::Done => Ok(()),
- })
- .cast()
}
}
@@ -151,12 +158,9 @@ any_trait! {
impl<'ctx, T, E: Environment> DeserializerWalker<'ctx, T, E>
where
T: Deserializer<'ctx> + 'ctx,
- E: EnvConfig<NeedSend = No, NeedSync = No>
+ E: EnvConfig<NeedSend = No, NeedSync = No>,
{
- fn call_deserialize<'visitor: 'e, 'e, F>(
- &'e mut self,
- f: F,
- ) -> NativeForm<'e, VisitResult, E>
+ fn call_deserialize<'visitor: 'e, 'e, F>(&'e mut self, f: F) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'visitor,
F: FnOnce(
@@ -169,17 +173,19 @@ where
match core::mem::replace(&mut self.inner, Inner::Temp) {
Inner::Init(deserializer) => {
match f(deserializer.0) {
- Ok(eff) => eff.map(self, |this, result| match result {
- (None, result) => {
- // Return the flow the visitor decided on.
- this.inner = Inner::Done;
- result
- }
- (Some(err), _) => {
- this.inner = Inner::Error(DeserializerWalkerError { inner: err });
- Flow::Err.into()
- }
- }).cast::<()>(),
+ Ok(eff) => eff
+ .map(self, |this, result| match result {
+ (None, result) => {
+ // Return the flow the visitor decided on.
+ this.inner = Inner::Done;
+ result
+ }
+ (Some(err), _) => {
+ this.inner = Inner::Error(DeserializerWalkerError { inner: err });
+ Flow::Err.into()
+ }
+ })
+ .cast::<()>(),
Err(err) => {
self.inner = Inner::Error(DeserializerWalkerError {
inner: VisitorError::Serde(Dynamic(err)),
@@ -253,7 +259,7 @@ impl_hints! {
impl<'ctx, T, E: Environment> Hint<'ctx, TagProto<tags::Map, E>> for DeserializerWalker<'ctx, T, E>
where
T: Deserializer<'ctx> + 'ctx,
- E: EnvConfig<NeedSend = No, NeedSync = No>
+ E: EnvConfig<NeedSend = No, NeedSync = No>,
{
fn hint<'this: 'e, 'visitor: 'e, 'hint: 'e, 'e>(
&'this mut self,
@@ -392,10 +398,9 @@ where
where
A: MapAccess<'ctx>,
{
- E::value((self, MapScope { map: Dynamic(map) }))
- .update((), |_, (this, scope)| {
- visit_sequence(this.visitor.cast(), scope).cast()
- });
+ E::value((self, MapScope { map: Dynamic(map) })).update((), |_, (this, scope)| {
+ visit_sequence(this.visitor.cast(), scope).cast()
+ });
todo!()
}
@@ -403,13 +408,13 @@ where
#[derive(SendSync)]
struct MapScope<A> {
- map: Dynamic<A>
+ map: Dynamic<A>,
}
-impl<'ctx, A, E: Environment> SequenceScope<'ctx, E> for MapScope<A>
+impl<'ctx, A, E: Environment> SequenceScope<'ctx, E> for MapScope<A>
where
E: EnvConfig<NeedSend = No, NeedSync = No>,
- A: MapAccess<'ctx>
+ A: MapAccess<'ctx>,
{
fn size_hint(&mut self) -> NativeForm<'_, (usize, Option<usize>), E> {
E::value((0, self.map.0.size_hint())).cast()
@@ -420,7 +425,8 @@ where
visitor: DynVisitor<'b, 'ctx, E>,
) -> NativeForm<'c, Flow, E>
where
- 'ctx: 'c + 'a + 'b {
+ 'ctx: 'c + 'a + 'b,
+ {
todo!()
}
}