Diffstat (limited to 'src/walk/walkers/serde/deserializer.rs')
-rw-r--r--src/walk/walkers/serde/deserializer.rs143
1 files changed, 75 insertions, 68 deletions
diff --git a/src/walk/walkers/serde/deserializer.rs b/src/walk/walkers/serde/deserializer.rs
index 70050d5..115ace1 100644
--- a/src/walk/walkers/serde/deserializer.rs
+++ b/src/walk/walkers/serde/deserializer.rs
@@ -1,12 +1,9 @@
+use effectful::{effective::NativeEffective, environment::{DynBind, Environment, NativeForm, EnvConfig}, SendSync, effective::Effective, bound::{No, Dynamic}};
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,
- ReadyExt as _, Ss,
- },
hkt::Marker,
protocol::{
visitor::{
@@ -19,6 +16,7 @@ use crate::{
Flow, Walker,
};
+#[derive(SendSync)]
pub struct DeserializerWalker<'ctx, T, E>
where
T: Deserializer<'ctx>,
@@ -27,28 +25,30 @@ where
_marker: Marker<E>,
}
+#[derive(SendSync)]
enum Inner<'ctx, T>
where
T: Deserializer<'ctx>,
{
Temp,
- Init(T),
+ Init(Dynamic<T>),
Error(DeserializerWalkerError<'ctx, T>),
Done,
}
-impl<'ctx, T, E: Effect> DeserializerWalker<'ctx, T, E>
+impl<'ctx, T, E: Environment> DeserializerWalker<'ctx, T, E>
where
T: Deserializer<'ctx>,
{
pub fn new(deserializer: T) -> Self {
Self {
- inner: Inner::Init(deserializer),
+ inner: Inner::Init(Dynamic(deserializer)),
_marker: Default::default(),
}
}
}
+#[derive(SendSync)]
pub struct DeserializerWalkerError<'ctx, T>
where
T: Deserializer<'ctx>,
@@ -74,7 +74,7 @@ where
VisitorError::i64(err) => write!(f, "{}", err),
VisitorError::i128(err) => write!(f, "{}", err),
VisitorError::isize(err) => write!(f, "{}", err),
- VisitorError::Serde(err) => write!(f, "{}", err),
+ VisitorError::Serde(err) => write!(f, "{}", err.0),
}
}
}
@@ -88,10 +88,10 @@ where
}
}
-impl<'ctx, T, E: Effect> Walker<'ctx, E> for DeserializerWalker<'ctx, T, E>
+impl<'ctx, T, E: Environment> Walker<'ctx, E> for DeserializerWalker<'ctx, T, E>
where
- T: Deserializer<'ctx> + Ss + 'ctx,
- T::Error: Ss,
+ T: Deserializer<'ctx> + 'ctx,
+ E: EnvConfig<NeedSend = No, NeedSync = No>,
{
type Error = DeserializerWalkerError<'ctx, T>;
@@ -99,35 +99,37 @@ where
fn walk<'visitor: 'effect, 'effect>(
self,
- visitor: DynVisitor<'visitor, 'ctx>,
- ) -> ErasedEffective<'effect, Result<Self::Output, Self::Error>, E>
+ visitor: DynVisitor<'visitor, 'ctx, E>,
+ ) -> NativeForm<'effect, Result<Self::Output, Self::Error>, E>
where
Self: 'effect,
{
- E::as_ctx((self, visitor), |(this, visitor)| {
+ 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(VisitResult::unit_skipped)
+ .map((), |_, x| VisitResult::unit_skipped(x))
.cast()
})
- .if_not_finished(|(this, visitor)| {
+ .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 {
+ .map((), |_, ((this, _), _)| match this.inner {
Inner::Temp => todo!(),
Inner::Init(_) => todo!(),
Inner::Error(err) => Err(err),
Inner::Done => Ok(()),
})
+ .cast()
}
}
any_trait! {
- impl['ctx, T, E] DeserializerWalker<'ctx, T, E> = [
+ impl['ctx, T][E] DeserializerWalker<'ctx, T, E> = [
HintProto<ValueProto<OwnedStatic<bool>, E>>,
HintProto<ValueProto<OwnedStatic<i8>, E>>,
HintProto<ValueProto<OwnedStatic<i16>, E>>,
@@ -142,55 +144,54 @@ any_trait! {
HintProto<ValueProto<OwnedStatic<char>, E>>,
HintProto<TagProto<tags::Map, E>>,
] where
- T: Deserializer<'ctx> + Ss + 'ctx,
- T::Error: Ss,
- E: Effect
+ T: Deserializer<'ctx> + 'ctx,
+ E: Environment<NeedSend = No, NeedSync = No>
}
-impl<'ctx, T, E: Effect> DeserializerWalker<'ctx, T, E>
+impl<'ctx, T, E: Environment> DeserializerWalker<'ctx, T, E>
where
- T: Deserializer<'ctx> + Ss + 'ctx,
- T::Error: Ss,
+ T: Deserializer<'ctx> + 'ctx,
+ E: EnvConfig<NeedSend = No, NeedSync = No>
{
fn call_deserialize<'visitor: 'e, 'e, F>(
&'e mut self,
f: F,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'visitor,
F: FnOnce(
T,
) -> Result<
- ErasedEffective<'visitor, (Option<VisitorError<'ctx, T>>, VisitResult), E>,
+ NativeForm<'visitor, (Option<VisitorError<'ctx, T>>, VisitResult), E>,
T::Error,
>,
{
match core::mem::replace(&mut self.inner, Inner::Temp) {
Inner::Init(deserializer) => {
- match f(deserializer) {
- Ok(eff) => eff.map(|result| match result {
+ match f(deserializer.0) {
+ Ok(eff) => eff.map(self, |this, result| match result {
(None, result) => {
// Return the flow the visitor decided on.
- self.inner = Inner::Done;
+ this.inner = Inner::Done;
result
}
(Some(err), _) => {
- self.inner = Inner::Error(DeserializerWalkerError { inner: err });
+ this.inner = Inner::Error(DeserializerWalkerError { inner: err });
Flow::Err.into()
}
- }),
+ }).cast::<()>(),
Err(err) => {
self.inner = Inner::Error(DeserializerWalkerError {
- inner: VisitorError::Serde(err),
+ inner: VisitorError::Serde(Dynamic(err)),
});
- E::ready(Flow::Err.into())
+ E::value(Flow::Err.into()).cast()
}
}
}
inner => {
// We really shouldn't be in this situation...
self.inner = inner;
- E::ready(VisitResult::Skipped(()))
+ E::value(VisitResult::Skipped(())).cast()
}
}
}
@@ -198,16 +199,16 @@ where
macro_rules! impl_hints {
(<$ctx:lifetime, $T:ident, $E:ident> $($proto:ty => $method:ident: $type:ty),* $(,)?) => {
- $(impl<$ctx, $T, $E: Effect> Hint<$ctx, $proto> for DeserializerWalker<$ctx, $T, $E>
+ $(impl<$ctx, $T, $E: Environment> Hint<$ctx, $proto> for DeserializerWalker<$ctx, $T, $E>
where
- $T: Deserializer<$ctx> + Ss + $ctx,
- $T::Error: Ss,
+ $T: Deserializer<$ctx> + $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>,
- ) -> ErasedEffective<'e, VisitResult, $E>
+ ) -> NativeForm<'e, VisitResult, $E>
where
$ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -217,8 +218,8 @@ macro_rules! impl_hints {
fn known<'a>(
&'a mut self,
_hint: &'a MetaHint<'a, 'ctx, $proto>,
- ) -> ErasedEffective<'a, Result<MetaKnown<'a, 'ctx, $proto>, ()>, $E> {
- E::ready(Ok(ValueKnown { preview: None }))
+ ) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, $proto>, ()>, $E> {
+ E::value(Ok(ValueKnown { preview: None })).cast()
}
})*
};
@@ -249,41 +250,42 @@ impl_hints! {
// ...
}
-impl<'ctx, T, E: Effect> Hint<'ctx, TagProto<tags::Map, E>> for DeserializerWalker<'ctx, T, E>
+impl<'ctx, T, E: Environment> Hint<'ctx, TagProto<tags::Map, E>> for DeserializerWalker<'ctx, T, E>
where
- T: Deserializer<'ctx> + Ss + 'ctx,
- T::Error: Ss,
+ T: Deserializer<'ctx> + '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>>,
- ) -> ErasedEffective<'e, VisitResult, <TagProto<tags::Map, E> as HintMeta>::Effect>
+ ) -> NativeForm<'e, VisitResult, <TagProto<tags::Map, E> as HintMeta>::Effect>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
// self.call_deserialize(|deserializer| {
// todo!()
// })
- VisitResult::Skipped(()).ready()
+ E::value(VisitResult::Skipped(())).cast()
}
fn known<'a>(
&'a mut self,
_hint: &'a MetaHint<'a, 'ctx, TagProto<tags::Map, E>>,
- ) -> ErasedEffective<
+ ) -> NativeForm<
'a,
Result<MetaKnown<'a, 'ctx, TagProto<tags::Map, E>>, ()>,
<TagProto<tags::Map, E> as HintMeta>::Effect,
> {
- Ok(TagKnown {
+ E::value(Ok(TagKnown {
kind_available: Some(true),
- })
- .ready()
+ }))
+ .cast()
}
}
#[allow(non_camel_case_types, unused)]
+#[derive(SendSync)]
enum VisitorError<'ctx, T>
where
T: Deserializer<'ctx>,
@@ -300,23 +302,24 @@ where
i64(IntegerWalkerError<i64>),
i128(IntegerWalkerError<i128>),
isize(IntegerWalkerError<isize>),
- Serde(T::Error),
+ Serde(Dynamic<T::Error>),
}
-struct Visitor<'temp, 'ctx, T, E>
+#[derive(SendSync)]
+struct Visitor<'temp, 'ctx, T, E: Environment>
where
T: Deserializer<'ctx>,
{
wanted: &'static str,
- visitor: DynVisitor<'temp, 'ctx>,
+ visitor: DynVisitor<'temp, 'ctx, E>,
_marker: Marker<(T, E)>,
}
-impl<'temp, 'ctx, T, E> Visitor<'temp, 'ctx, T, E>
+impl<'temp, 'ctx, T, E: Environment> Visitor<'temp, 'ctx, T, E>
where
T: Deserializer<'ctx>,
{
- pub fn new(visitor: DynVisitor<'temp, 'ctx>, wanted: &'static str) -> Self {
+ pub fn new(visitor: DynVisitor<'temp, 'ctx, E>, wanted: &'static str) -> Self {
Self {
wanted,
visitor,
@@ -332,7 +335,7 @@ macro_rules! impl_visits {
Err: serde::de::Error,
{
// Visit the treaty visitor with the value serde gave.
- Ok(visit_value::<_, E>(self.visitor, OwnedStatic(v)).map(|result| (None, result.unit_skipped())))
+ Ok(visit_value::<_, E>(self.visitor, OwnedStatic(v)).map((), |_, result| (None, result.unit_skipped())).cast())
})*
};
// Many serde deserializers (like serde_json) don't follow the hint given when visiting.
@@ -343,20 +346,20 @@ 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::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())
})*
};
}
-impl<'temp, 'ctx, T: Deserializer<'ctx> + 'temp, E: Effect> serde::de::Visitor<'ctx>
+impl<'temp, 'ctx, T: Deserializer<'ctx> + 'temp, E: Environment> serde::de::Visitor<'ctx>
for Visitor<'temp, 'ctx, T, E>
where
- T::Error: Ss,
+ E: EnvConfig<NeedSend = No, NeedSync = No>,
{
- type Value = ErasedEffective<'temp, (Option<VisitorError<'ctx, T>>, VisitResult), E>;
+ 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)
@@ -389,29 +392,33 @@ where
where
A: MapAccess<'ctx>,
{
- let mut scope = MapScope { map };
- visit_sequence(self.visitor, &mut scope);
+ E::value((self, MapScope { map: Dynamic(map) }))
+ .update((), |_, (this, scope)| {
+ visit_sequence(this.visitor.cast(), scope).cast()
+ });
todo!()
}
}
+#[derive(SendSync)]
struct MapScope<A> {
- map: A
+ map: Dynamic<A>
}
-impl<'ctx, A, E: Effect> 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>
{
- fn size_hint(&mut self) -> ErasedEffective<'_, (usize, Option<usize>), E> {
- (0, self.map.size_hint()).ready()
+ fn size_hint(&mut self) -> NativeForm<'_, (usize, Option<usize>), E> {
+ E::value((0, self.map.0.size_hint())).cast()
}
fn next<'a: 'c, 'b: 'c, 'c>(
&'a mut self,
- visitor: DynVisitor<'b, 'ctx>,
- ) -> ErasedEffective<'c, Flow, E>
+ visitor: DynVisitor<'b, 'ctx, E>,
+ ) -> NativeForm<'c, Flow, E>
where
'ctx: 'c + 'a + 'b {
todo!()