Diffstat (limited to 'src/walk/walkers/serde/deserializer.rs')
-rw-r--r--src/walk/walkers/serde/deserializer.rs156
1 files changed, 89 insertions, 67 deletions
diff --git a/src/walk/walkers/serde/deserializer.rs b/src/walk/walkers/serde/deserializer.rs
index 32e58f1..4537e07 100644
--- a/src/walk/walkers/serde/deserializer.rs
+++ b/src/walk/walkers/serde/deserializer.rs
@@ -1,9 +1,9 @@
-use crate::walkers::core::noop::NoopWalker;
+use crate::walk::walkers::core::noop::NoopWalker;
use effectful::{
- bound::{Dynamic, HasSendAndSync, No},
+ bound::{Dynamic, No},
effective::Effective,
- effective::NativeEffective,
environment::{DynBind, EnvConfig, Environment, NativeForm},
+ higher_ranked::{Rank1, WithLt},
SendSync,
};
use serde::{
@@ -12,18 +12,17 @@ use serde::{
};
use crate::{
- any::{BorrowedStaticHrt, OwnedStatic, TempBorrowedStatic, TempBorrowedStaticHrt, TypeName},
- any_trait,
+ any::{type_name, AnyTrait, BorrowedStatic, OwnedStatic, TempBorrowedStatic},
hkt::Marker,
protocol::{
visitor::{
request_hint, tags, visit_sequence, visit_tag, visit_value, EffectiveVisitExt as _,
- SequenceScope, TagConst, TagKnown, TagProto, ValueKnown, ValueProto, VisitResult,
+ SequenceScope, Tag, TagConst, TagHint, TagKnown, Value, ValueKnown, VisitResult,
},
- walker::hint::{DynVisitorWith, Hint, HintMeta, HintProto, MetaHint, MetaKnown},
+ walker::hint::{DynVisitorWith, Hint, HintMeta},
DynVisitor, DynWalker,
},
- walkers::core::int::IntegerWalkerError,
+ walk::walkers::core::int::IntegerWalkerError,
Flow, Walker,
};
@@ -140,31 +139,39 @@ where
}
}
-any_trait! {
- impl['ctx, T][E] DeserializerWalker<'ctx, T, E> = [
- HintProto<ValueProto<OwnedStatic<bool>, E>>,
- // HintProto<ValueProto<OwnedStatic<i8>, E>>,
- // HintProto<ValueProto<OwnedStatic<i16>, E>>,
- // HintProto<ValueProto<OwnedStatic<i32>, E>>,
- // HintProto<ValueProto<OwnedStatic<i64>, E>>,
- // HintProto<ValueProto<OwnedStatic<i128>, E>>,
- // HintProto<ValueProto<OwnedStatic<u8>, E>>,
- // HintProto<ValueProto<OwnedStatic<u16>, E>>,
- // HintProto<ValueProto<OwnedStatic<u32>, E>>,
- // HintProto<ValueProto<OwnedStatic<u64>, E>>,
- // HintProto<ValueProto<OwnedStatic<u128>, E>>,
- // HintProto<ValueProto<OwnedStatic<char>, E>>,
- // HintProto<TagProto<tags::Map, E>>,
- ] where
- T: Deserializer<'ctx>,
- E: Environment<NeedSend = No, NeedSync = No>
+impl<'ctx, T, E> AnyTrait<'ctx> for DeserializerWalker<'ctx, T, E>
+where
+ T: Deserializer<'ctx>,
+ E: Environment<NeedSend = No, NeedSync = No>,
+{
}
+// any_trait! {
+// impl['ctx, T][E] DeserializerWalker<'ctx, T, E> = [
+// HintProto<ValueProto<OwnedStatic<bool>, E>>,
+// HintProto<ValueProto<OwnedStatic<i8>, E>>,
+// HintProto<ValueProto<OwnedStatic<i16>, E>>,
+// HintProto<ValueProto<OwnedStatic<i32>, E>>,
+// HintProto<ValueProto<OwnedStatic<i64>, E>>,
+// HintProto<ValueProto<OwnedStatic<i128>, E>>,
+// HintProto<ValueProto<OwnedStatic<u8>, E>>,
+// HintProto<ValueProto<OwnedStatic<u16>, E>>,
+// HintProto<ValueProto<OwnedStatic<u32>, E>>,
+// HintProto<ValueProto<OwnedStatic<u64>, E>>,
+// HintProto<ValueProto<OwnedStatic<u128>, E>>,
+// HintProto<ValueProto<OwnedStatic<char>, E>>,
+// HintProto<TagProto<tags::Map, E>>,
+// ] where
+// T: Deserializer<'ctx>,
+// E: Environment<NeedSend = No, NeedSync = No>
+// }
+
impl<'ctx, T, E: Environment> DeserializerWalker<'ctx, T, E>
where
T: Deserializer<'ctx>,
E: EnvConfig<NeedSend = No, NeedSync = No>,
{
+ #[allow(clippy::type_complexity)]
fn call_deserialize<'this: 'e, 'e, Cap>(
&'this mut self,
cap: Cap,
@@ -220,15 +227,15 @@ where
macro_rules! impl_hints {
(<$ctx:lifetime, $T:ident, $E:ident> $($proto:ty => $method:ident: $type:ty),* $(,)?) => {
- $(impl<$ctx, $T, $E: Environment> Hint<$ctx, $proto> for DeserializerWalker<$ctx, $T, $E>
+ $(impl<$ctx, $T, $E: Environment> Hint<$ctx, type_name::Raised<'static, $ctx, $proto>> for DeserializerWalker<$ctx, $T, $E>
where
$T: Deserializer<$ctx>,
$E: EnvConfig<NeedSend = No, NeedSync = No>
{
fn hint<'this: 'e, 'visitor: 'e, 'hint: 'e, 'e>(
&'this mut self,
- visitor: DynVisitorWith<'visitor, $ctx, $proto>,
- _hint: MetaHint<'hint, $ctx, $proto>,
+ visitor: DynVisitorWith<'visitor, $ctx, type_name::Raised<'static, $ctx, $proto>>,
+ _hint: WithLt<'hint, <type_name::Raised<'static, $ctx, $proto> as HintMeta>::Hint>,
) -> NativeForm<'e, VisitResult, $E>
where
$ctx: 'this + 'visitor + 'hint + 'e,
@@ -247,8 +254,11 @@ macro_rules! impl_hints {
fn known<'a>(
&'a mut self,
- _hint: &'a MetaHint<'a, 'ctx, $proto>,
- ) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, $proto>, ()>, $E> {
+ _hint: &'a WithLt<'a, <type_name::Raised<'static, $ctx, $proto> as HintMeta>::Hint>,
+ ) -> NativeForm<'a, Result<WithLt<'a, <type_name::Raised<'static, $ctx, $proto> as HintMeta>::Known>, ()>, $E>
+ where
+ WithLt<'a, <type_name::Raised<'static, $ctx, $proto> as HintMeta>::Known>: DynBind<$E>
+ {
E::value(Ok(ValueKnown { preview: None })).cast()
}
})*
@@ -257,39 +267,45 @@ macro_rules! impl_hints {
impl_hints! {
<'ctx, T, E>
- ValueProto<OwnedStatic<bool>, E> => deserialize_bool: bool,
- ValueProto<OwnedStatic<i8>, E> => deserialize_i8: i8,
- ValueProto<OwnedStatic<i16>, E> => deserialize_i16: i16,
- ValueProto<OwnedStatic<i32>, E> => deserialize_i32: i32,
- ValueProto<OwnedStatic<i64>, E> => deserialize_i64: i64,
- ValueProto<OwnedStatic<i128>, E> => deserialize_i128: i128,
- ValueProto<OwnedStatic<u8>, E> => deserialize_u8: u8,
- ValueProto<OwnedStatic<u16>, E> => deserialize_u16: u16,
- ValueProto<OwnedStatic<u32>, E> => deserialize_u32: u32,
- ValueProto<OwnedStatic<u64>, E> => deserialize_u64: u64,
- ValueProto<OwnedStatic<u128>, E> => deserialize_u128: u128,
- ValueProto<OwnedStatic<f32>, E> => deserialize_f32: f32,
- ValueProto<OwnedStatic<f64>, E> => deserialize_f64: f64,
- ValueProto<OwnedStatic<char>, E> => deserialize_char: char,
- ValueProto<TempBorrowedStaticHrt<str>, E> => deserialize_str: &str,
- ValueProto<BorrowedStaticHrt<str>, E> => deserialize_str: &str,
- ValueProto<OwnedStatic<String>, E> => deserialize_string: String,
- ValueProto<TempBorrowedStaticHrt<[u8]>, E> => deserialize_bytes: &[u8],
- ValueProto<BorrowedStaticHrt<[u8]>, E> => deserialize_bytes: &[u8],
- ValueProto<OwnedStatic<Vec<u8>>, E> => deserialize_byte_buf: Vec<u8>,
+ dyn Value<'ctx, OwnedStatic<bool>, E> => deserialize_bool: bool,
+ dyn Value<'ctx, OwnedStatic<i8>, E> => deserialize_i8: i8,
+ dyn Value<'ctx, OwnedStatic<i16>, E> => deserialize_i16: i16,
+ dyn Value<'ctx, OwnedStatic<i32>, E> => deserialize_i32: i32,
+ dyn Value<'ctx, OwnedStatic<i64>, E> => deserialize_i64: i64,
+ dyn Value<'ctx, OwnedStatic<i128>, E> => deserialize_i128: i128,
+ dyn Value<'ctx, OwnedStatic<u8>, E> => deserialize_u8: u8,
+ dyn Value<'ctx, OwnedStatic<u16>, E> => deserialize_u16: u16,
+ dyn Value<'ctx, OwnedStatic<u32>, E> => deserialize_u32: u32,
+ dyn Value<'ctx, OwnedStatic<u64>, E> => deserialize_u64: u64,
+ dyn Value<'ctx, OwnedStatic<u128>, E> => deserialize_u128: u128,
+ dyn Value<'ctx, OwnedStatic<f32>, E> => deserialize_f32: f32,
+ dyn Value<'ctx, OwnedStatic<f64>, E> => deserialize_f64: f64,
+ dyn Value<'ctx, OwnedStatic<char>, E> => deserialize_char: char,
+ dyn Value<'ctx, type_name::Raised<'static, 'ctx, TempBorrowedStatic<'static, str>>, E> => deserialize_str: &str,
+ dyn Value<'ctx, type_name::Raised<'static, 'ctx, BorrowedStatic<'ctx, str>>, E> => deserialize_str: &str,
+ dyn Value<'ctx, OwnedStatic<String>, E> => deserialize_string: String,
+ dyn Value<'ctx, type_name::Raised<'static, 'ctx, TempBorrowedStatic<'static, [u8]>>, E> => deserialize_bytes: &[u8],
+ dyn Value<'ctx, type_name::Raised<'static, 'ctx, BorrowedStatic<'ctx, [u8]>>, E> => deserialize_bytes: &[u8],
+ dyn Value<'ctx, OwnedStatic<Vec<u8>>, E> => deserialize_byte_buf: Vec<u8>,
// ...
}
-impl<'ctx, T, E: Environment> Hint<'ctx, TagProto<tags::Map, E>> for DeserializerWalker<'ctx, T, E>
+impl<'ctx, T, E: Environment>
+ Hint<'ctx, type_name::Raised<'static, 'ctx, dyn Tag<'ctx, tags::Map, E>>>
+ for DeserializerWalker<'ctx, T, E>
where
T: Deserializer<'ctx>,
E: EnvConfig<NeedSend = No, NeedSync = No>,
{
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>>,
- ) -> NativeForm<'e, VisitResult, <TagProto<tags::Map, E> as HintMeta>::Effect>
+ _visitor: DynVisitorWith<
+ 'visitor,
+ 'ctx,
+ type_name::Raised<'static, 'ctx, dyn Tag<'ctx, tags::Map, E>>,
+ >,
+ _hint: TagHint<tags::Map>,
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -301,12 +317,11 @@ where
fn known<'a>(
&'a mut self,
- _hint: &'a MetaHint<'a, 'ctx, TagProto<tags::Map, E>>,
- ) -> NativeForm<
- 'a,
- Result<MetaKnown<'a, 'ctx, TagProto<tags::Map, E>>, ()>,
- <TagProto<tags::Map, E> as HintMeta>::Effect,
- > {
+ _hint: &'a WithLt<'a, Rank1<TagHint<tags::Map>>>,
+ ) -> NativeForm<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, E>
+ where
+ WithLt<'a, Rank1<TagKnown>>: DynBind<E>,
+ {
E::value(Ok(TagKnown {
kind_available: Some(true),
}))
@@ -376,7 +391,7 @@ macro_rules! impl_visits {
Err: serde::de::Error,
{
// This will attempt every native integer type until the visitor accepts one of them.
- Ok($crate::walkers::core::int::IntegerWalker::<_, E>::new(v).walk(self.visitor).map((), |_, result| match result {
+ Ok($crate::walk::walkers::core::int::IntegerWalker::<_, E>::new(v).walk(self.visitor).map((), |_, result| match result {
Ok(_) => (None, Flow::Done.into()),
Err(err) => (Some(VisitorError::$type(err)), Flow::Err.into())
}).cast())
@@ -392,7 +407,7 @@ where
type Value = NativeForm<'temp, (Option<VisitorError<'ctx, T>>, VisitResult), E>;
fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- formatter.write_str(&self.wanted)
+ formatter.write_str(self.wanted)
}
impl_visits! {
@@ -418,6 +433,13 @@ where
visit_u128: u128,
}
+ fn visit_str<Err>(self, _v: &str) -> Result<Self::Value, Err>
+ where
+ Err: serde::de::Error,
+ {
+ todo!()
+ }
+
fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'ctx>,
@@ -471,7 +493,7 @@ where
if x.unwrap().is_some() {
// There is another item.
- let x = self.map.0.next_value_seed(ValueDeserialize { visitor });
+ let _x = self.map.0.next_value_seed(ValueDeserialize { visitor });
// dbg!(x);
E::value(Flow::Continue).cast()
} else {
@@ -501,7 +523,7 @@ where
// so we must block instead. This should be fine as serde itself isn't async
// normally.
- let x = visit_tag::<tags::Key, E, _>(TagConst, self.visitor.cast(), walker)
+ let _x = visit_tag::<tags::Key, E, _>(TagConst, self.visitor.cast(), walker)
.map((), |_, result| match result {
Ok(visit) => visit.unit_skipped(),
Err(_) => Flow::Err.into(),
@@ -531,9 +553,9 @@ where
// We have a deserializer and we know how to handle those!
let walker = DeserializerWalker::<'_, _, E>::new(deserializer);
- let x = walker.walk(self.visitor).wait();
+ let _x = walker.walk(self.visitor).wait();
- dbg!(x);
+ // dbg!(x);
Ok(())
}