Diffstat (limited to 'src/walk/walkers/serde/deserializer.rs')
-rw-r--r--src/walk/walkers/serde/deserializer.rs91
1 files changed, 82 insertions, 9 deletions
diff --git a/src/walk/walkers/serde/deserializer.rs b/src/walk/walkers/serde/deserializer.rs
index 5a481e0..70050d5 100644
--- a/src/walk/walkers/serde/deserializer.rs
+++ b/src/walk/walkers/serde/deserializer.rs
@@ -1,14 +1,17 @@
-use serde::Deserializer;
+use serde::{de::MapAccess, Deserializer};
use crate::{
any::{BorrowedStaticHrt, OwnedStatic, TempBorrowedStatic, TempBorrowedStaticHrt, TypeName},
any_trait,
effect::{
- BlockOn, Effect, EffectExt as _, Effective as _, EffectiveExt as _, ErasedEffective, Ss,
+ BlockOn, Effect, EffectExt as _, Effective as _, EffectiveExt as _, ErasedEffective,
+ ReadyExt as _, Ss,
},
hkt::Marker,
protocol::{
- visitor::{request_hint, visit_value, ValueKnown, ValueProto, VisitResult},
+ visitor::{
+ 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,
},
@@ -108,6 +111,12 @@ where
.map(VisitResult::unit_skipped)
.cast()
})
+ .if_not_finished(|(this, visitor)| {
+ this.call_deserialize(|deserializer| {
+ deserializer.deserialize_any(Visitor::<T, E>::new(visitor.cast(), "any"))
+ })
+ .cast()
+ })
.map(|((this, _), _)| match this.inner {
Inner::Temp => todo!(),
Inner::Init(_) => todo!(),
@@ -131,6 +140,7 @@ any_trait! {
HintProto<ValueProto<OwnedStatic<u64>, E>>,
HintProto<ValueProto<OwnedStatic<u128>, E>>,
HintProto<ValueProto<OwnedStatic<char>, E>>,
+ HintProto<TagProto<tags::Map, E>>,
] where
T: Deserializer<'ctx> + Ss + 'ctx,
T::Error: Ss,
@@ -201,7 +211,7 @@ macro_rules! impl_hints {
where
$ctx: 'this + 'visitor + 'hint + 'e,
{
- self.call_deserialize(|deserializer| deserializer.$method(Visitor::new(visitor, stringify!($type))))
+ self.call_deserialize(|deserializer| deserializer.$method(Visitor::<$T, $E>::new(visitor.into_inner(), stringify!($type))))
}
fn known<'a>(
@@ -239,6 +249,40 @@ impl_hints! {
// ...
}
+impl<'ctx, T, E: Effect> Hint<'ctx, TagProto<tags::Map, E>> for DeserializerWalker<'ctx, T, E>
+where
+ T: Deserializer<'ctx> + Ss + 'ctx,
+ T::Error: Ss,
+{
+ fn hint<'this: 'e, 'visitor: 'e, 'hint: 'e, 'e>(
+ &'this mut self,
+ visitor: DynVisitorWith<'visitor, 'ctx, TagProto<tags::Map, E>>,
+ hint: MetaHint<'hint, 'ctx, TagProto<tags::Map, E>>,
+ ) -> ErasedEffective<'e, VisitResult, <TagProto<tags::Map, E> as HintMeta>::Effect>
+ where
+ 'ctx: 'this + 'visitor + 'hint + 'e,
+ {
+ // self.call_deserialize(|deserializer| {
+ // todo!()
+ // })
+ VisitResult::Skipped(()).ready()
+ }
+
+ fn known<'a>(
+ &'a mut self,
+ _hint: &'a MetaHint<'a, 'ctx, TagProto<tags::Map, E>>,
+ ) -> ErasedEffective<
+ 'a,
+ Result<MetaKnown<'a, 'ctx, TagProto<tags::Map, E>>, ()>,
+ <TagProto<tags::Map, E> as HintMeta>::Effect,
+ > {
+ Ok(TagKnown {
+ kind_available: Some(true),
+ })
+ .ready()
+ }
+}
+
#[allow(non_camel_case_types, unused)]
enum VisitorError<'ctx, T>
where
@@ -272,13 +316,10 @@ impl<'temp, 'ctx, T, E> Visitor<'temp, 'ctx, T, E>
where
T: Deserializer<'ctx>,
{
- pub fn new<Protocol: HintMeta<Effect = E>>(
- visitor: DynVisitorWith<'temp, 'ctx, Protocol>,
- wanted: &'static str,
- ) -> Self {
+ pub fn new(visitor: DynVisitor<'temp, 'ctx>, wanted: &'static str) -> Self {
Self {
wanted,
- visitor: visitor.into_inner(),
+ visitor,
_marker: Default::default(),
}
}
@@ -343,4 +384,36 @@ where
visit_u64: u64,
visit_u128: u128,
}
+
+ fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error>
+ where
+ A: MapAccess<'ctx>,
+ {
+ let mut scope = MapScope { map };
+ visit_sequence(self.visitor, &mut scope);
+
+ todo!()
+ }
+}
+
+struct MapScope<A> {
+ map: A
+}
+
+impl<'ctx, A, E: Effect> SequenceScope<'ctx, E> for MapScope<A>
+where
+ A: MapAccess<'ctx>
+{
+ fn size_hint(&mut self) -> ErasedEffective<'_, (usize, Option<usize>), E> {
+ (0, self.map.size_hint()).ready()
+ }
+
+ fn next<'a: 'c, 'b: 'c, 'c>(
+ &'a mut self,
+ visitor: DynVisitor<'b, 'ctx>,
+ ) -> ErasedEffective<'c, Flow, E>
+ where
+ 'ctx: 'c + 'a + 'b {
+ todo!()
+ }
}