removed need for every value to implement IsSend and IsSync
Konnor Andrews 2024-07-06
parent 5ab752d · commit 3e84ea5
-rw-r--r--src/any.rs4
-rw-r--r--src/any/static_wrapper.rs24
-rw-r--r--src/build.rs10
-rw-r--r--src/build/builders/core/bool.rs20
-rw-r--r--src/build/builders/core/enum.rs54
-rw-r--r--src/build/builders/core/struct.rs84
-rw-r--r--src/build/builders/core/value.rs95
-rw-r--r--src/macros/build.rs116
-rw-r--r--src/protocol/visitor/request_hint.rs10
-rw-r--r--src/protocol/visitor/value.rs18
-rw-r--r--src/transform.rs8
-rw-r--r--src/walk/walkers.rs4
-rw-r--r--src/walk/walkers/core/bool.rs17
-rw-r--r--src/walk/walkers/core/int.rs96
-rw-r--r--src/walk/walkers/core/struct.rs30
-rw-r--r--src/walk/walkers/core/value.rs28
-rw-r--r--src/walk/walkers/serde/deserializer.rs143
-rw-r--r--tests/builder_enum.rs8
-rw-r--r--tests/builder_struct.rs6
-rw-r--r--tests/builder_value.rs2
-rw-r--r--tests/common/builder.rs24
-rw-r--r--tests/common/protocol/value.rs14
-rw-r--r--tests/protocol_visitor_request_hint.rs5
-rw-r--r--tests/protocol_visitor_value.rs11
-rw-r--r--tests/serde_deserializer.rs83
-rw-r--r--tests/walker_struct.rs8
26 files changed, 605 insertions, 317 deletions
diff --git a/src/any.rs b/src/any.rs
index 231da6c..00249bc 100644
--- a/src/any.rs
+++ b/src/any.rs
@@ -27,7 +27,7 @@ pub enum LifetimeType {}
pub mod TypeName {
use effectful::environment::{DynBind, EnvConfig};
- pub trait MemberTypeForLt<'a, 'ctx: 'a, E: EnvConfig, B>: DynBind<E> {
+ pub trait MemberTypeForLt<'a, 'ctx: 'a, E: EnvConfig, B> {
type T: ?Sized + LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx (), Higher = Self>;
}
@@ -41,7 +41,7 @@ pub mod TypeName {
{
}
- pub trait LowerTypeWithBound<'a, 'ctx: 'a, E: EnvConfig, B>: 'a + DynBind<E> {
+ pub trait LowerTypeWithBound<'a, 'ctx: 'a, E: EnvConfig, B>: 'a {
type Higher: ?Sized + MemberTypeForLt<'a, 'ctx, E, &'a &'ctx (), T = Self> + 'static;
}
diff --git a/src/any/static_wrapper.rs b/src/any/static_wrapper.rs
index 6184509..4497fbd 100644
--- a/src/any/static_wrapper.rs
+++ b/src/any/static_wrapper.rs
@@ -14,7 +14,7 @@ pub struct OwnedStatic<T: ?Sized>(pub T);
impl<'a, 'ctx, E: EnvConfig, T> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>
for OwnedStatic<T>
where
- T: DynBind<E> + 'static,
+ T: 'static,
{
type T = OwnedStatic<T>;
}
@@ -22,7 +22,7 @@ where
impl<'a, 'ctx, E: EnvConfig, T> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>
for OwnedStatic<T>
where
- T: DynBind<E> + 'static,
+ T: 'static,
{
type Higher = OwnedStatic<T>;
}
@@ -38,7 +38,7 @@ pub struct BorrowedStaticHrt<T: ?Sized>(Marker<T>);
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>
for BorrowedStaticHrt<T>
where
- T: DynBind<E> + IsSync<E::NeedSend> + 'static,
+ T: 'static,
{
type T = BorrowedStatic<'ctx, T>;
}
@@ -46,7 +46,7 @@ where
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>
for BorrowedStatic<'ctx, T>
where
- T: DynBind<E> + IsSync<E::NeedSend> + 'static,
+ T: 'static,
{
type Higher = BorrowedStaticHrt<T>;
}
@@ -62,7 +62,7 @@ pub struct TempBorrowedStaticHrt<T: ?Sized>(Marker<T>);
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>
for TempBorrowedStaticHrt<T>
where
- T: DynBind<E> + IsSync<E::NeedSend> + 'static,
+ T: 'static,
{
type T = TempBorrowedStatic<'a, T>;
}
@@ -70,7 +70,7 @@ where
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>
for TempBorrowedStatic<'a, T>
where
- T: DynBind<E> + IsSync<E::NeedSend> + 'static,
+ T: 'static,
{
type Higher = TempBorrowedStaticHrt<T>;
}
@@ -86,7 +86,7 @@ pub struct BorrowedMutStaticHrt<T: ?Sized>(Marker<T>);
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>
for BorrowedMutStaticHrt<T>
where
- T: DynBind<E> + 'static,
+ T: 'static,
{
type T = BorrowedMutStatic<'ctx, T>;
}
@@ -94,7 +94,7 @@ where
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>
for BorrowedMutStatic<'ctx, T>
where
- T: DynBind<E> + 'static,
+ T: 'static,
{
type Higher = BorrowedMutStaticHrt<T>;
}
@@ -110,7 +110,7 @@ pub struct TempBorrowedMutStaticHrt<T: ?Sized>(Marker<T>);
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>
for TempBorrowedMutStaticHrt<T>
where
- T: DynBind<E> + 'static,
+ T: 'static,
{
type T = TempBorrowedMutStatic<'a, T>;
}
@@ -118,7 +118,7 @@ where
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>
for TempBorrowedMutStatic<'a, T>
where
- T: DynBind<E> + 'static,
+ T: 'static,
{
type Higher = TempBorrowedMutStaticHrt<T>;
}
@@ -133,7 +133,7 @@ pub struct BoxedStatic<T: ?Sized>(pub Box<T>);
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>
for BoxedStatic<T>
where
- T: DynBind<E> + 'static,
+ T: 'static,
{
type T = BoxedStatic<T>;
}
@@ -142,7 +142,7 @@ where
impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>
for BoxedStatic<T>
where
- T: DynBind<E> + 'static,
+ T: 'static,
{
type Higher = BoxedStatic<T>;
}
diff --git a/src/build.rs b/src/build.rs
index eca91af..2cd87ea 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -6,7 +6,7 @@ use effectful::environment::{DynBind, EnvConfig, Environment, NativeForm};
use crate::protocol::{AsVisitor, DynVisitor};
/// A buildable type.
-pub trait Build<'ctx, M, E: Environment>: Sized + DynBind<E> {
+pub trait Build<'ctx, M, E: Environment>: Sized {
/// The builder that can be used to build a value of `Self`.
type Builder: Builder<'ctx, E, Value = Self>;
}
@@ -17,8 +17,12 @@ pub trait BuilderTypes<C: EnvConfig> {
/// Error that can happen during filling the builder with data.
type Error: DynBind<C> + Debug + Display;
+ type Output: DynBind<C>;
+
/// Type to be built.
- type Value: DynBind<C>;
+ type Value;
+
+ fn unwrap_output(output: Self::Output) -> Self::Value;
}
/// Builder for a type.
@@ -45,7 +49,7 @@ pub trait Builder<'ctx, E: Environment>:
///
/// If an error happened with the builder during the walk
/// it will be reported here.
- fn build<'a>(self) -> NativeForm<'a, Result<Self::Value, Self::Error>, E>
+ fn build<'a>(self) -> NativeForm<'a, Result<Self::Output, Self::Error>, E>
where
Self: 'a;
}
diff --git a/src/build/builders/core/bool.rs b/src/build/builders/core/bool.rs
index b09e4cb..4f8f2f0 100644
--- a/src/build/builders/core/bool.rs
+++ b/src/build/builders/core/bool.rs
@@ -1,9 +1,25 @@
use super::value::{Cloneable, ValueBuilder};
-use effectful::environment::Environment;
+use effectful::environment::{Environment, DynBind};
+use effectful::bound::{Dynamic, IsSync};
+use crate::any::{OwnedStatic, BorrowedStatic, TempBorrowedStatic, BorrowedMutStatic, TempBorrowedMutStatic};
macro_rules! value_builder {
[$($ty:ty),*] => {
- $(impl<'ctx, M, E: Environment> crate::Build<'ctx, M, E> for $ty {
+ $(impl<'ctx, M, E: Environment> crate::Build<'ctx, M, E> for $ty
+ where
+ Dynamic<Self>: DynBind<E>,
+ for<'a> Dynamic<&'a Self>: DynBind<E>,
+ Dynamic<OwnedStatic<Self>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<Self>>: DynBind<E>,
+ Dynamic<BorrowedStatic<'ctx, Self>>: DynBind<E>,
+ for<'a, 'b> Dynamic<&'a BorrowedStatic<'b, Self>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, Self>>: DynBind<E>,
+ for<'a> Dynamic<&'a TempBorrowedStatic<'a, Self>>: DynBind<E>,
+ Dynamic<BorrowedMutStatic<'ctx, Self>>: DynBind<E>,
+ for<'a, 'b> Dynamic<&'a BorrowedMutStatic<'b, Self>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedMutStatic<'a, Self>>: DynBind<E>,
+ for<'a> Dynamic<&'a TempBorrowedMutStatic<'a, Self>>: DynBind<E>,
+ {
type Builder = ValueBuilder<$ty, Cloneable, E>;
})*
};
diff --git a/src/build/builders/core/enum.rs b/src/build/builders/core/enum.rs
index da66e9d..4294fff 100644
--- a/src/build/builders/core/enum.rs
+++ b/src/build/builders/core/enum.rs
@@ -1,6 +1,6 @@
use core::fmt::{Debug, Display};
-use effectful::bound::{Bool, IsSend, IsSync};
+use effectful::bound::{Bool, IsSend, IsSync, Dynamic};
use effectful::effective::Effective;
use effectful::environment::{DynBind, Environment, NativeForm};
use effectful::higher_ranked::Mut;
@@ -36,7 +36,7 @@ where
Temp,
Seed(Info::Seed),
Builder { builder: Info::Builders },
- Value(Result<Info::T, Info::Error>),
+ Value(Result<Dynamic<Info::T>, Info::Error>),
}
pub trait EnumBuildInfo<'ctx, Mode, E: Environment> {
@@ -48,7 +48,7 @@ pub trait EnumBuildInfo<'ctx, Mode, E: Environment> {
type ValueT: TypeName::MemberType<E>;
- type T: DynBind<E>;
+ type T;
type VariantMarker: DynBind<E> + Copy + Display;
@@ -59,7 +59,9 @@ pub trait EnumBuildInfo<'ctx, Mode, E: Environment> {
fn finish_builder<'a>(
builder: Self::Builders,
- ) -> NativeForm<'a, Result<Self::T, Self::Error>, E>;
+ ) -> NativeForm<'a, Result<Dynamic<Self::T>, Self::Error>, E>
+ where
+ Dynamic<Self::T>: DynBind<E>;
fn from_value<'a>(value: TypeName::T<'a, 'ctx, Self::ValueT, E>) -> Self::T;
@@ -72,23 +74,36 @@ pub trait EnumBuildInfo<'ctx, Mode, E: Environment> {
fn guess_variant<'a>(
seed: Self::Seed,
scope: DynRecoverableScope<'a, 'ctx, E>,
- ) -> NativeForm<'a, Result<Self::T, Self::Error>, E>;
+ ) -> NativeForm<'a, Result<Dynamic<Self::T>, Self::Error>, E>
+ where
+ Dynamic<Self::T>: DynBind<E>;
}
impl<'ctx, Info, Mode, E: Environment> BuilderTypes<E> for EnumBuilder<'ctx, Info, Mode, E>
where
Info: EnumBuildInfo<'ctx, Mode, E>,
+ Dynamic<Info::T>: DynBind<E>
{
type Seed = Info::Seed;
type Error = Info::Error;
type Value = Info::T;
+
+ type Output = Dynamic<Info::T>;
+
+ fn unwrap_output(output: Self::Output) -> Self::Value {
+ output.0
+ }
}
impl<'ctx, Info, Mode, E: Environment> Builder<'ctx, E> for EnumBuilder<'ctx, Info, Mode, E>
where
Info: EnumBuildInfo<'ctx, Mode, E>,
+ Dynamic<Info::T>: DynBind<E>,
+ for<'a> Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>,
+ Dynamic<OwnedStatic<u32>>: DynBind<E>,
{
fn from_seed<'a>(seed: Self::Seed) -> NativeForm<'a, Self, E>
where
@@ -100,7 +115,7 @@ where
.cast()
}
- fn build<'a>(self) -> NativeForm<'a, Result<Self::Value, Self::Error>, E>
+ fn build<'a>(self) -> NativeForm<'a, Result<Self::Output, Self::Error>, E>
where
Self: 'a,
{
@@ -119,6 +134,10 @@ where
impl<'ctx, Info, Mode, E: Environment> AsVisitor<'ctx, E> for EnumBuilder<'ctx, Info, Mode, E>
where
Info: EnumBuildInfo<'ctx, Mode, E>,
+ Dynamic<Info::T>: DynBind<E>,
+ for<'a> Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>,
+ Dynamic<OwnedStatic<u32>>: DynBind<E>,
{
fn as_visitor<'a>(&'a mut self) -> DynVisitor<'a, 'ctx, E>
where
@@ -154,11 +173,16 @@ any_trait! {
} where
E: Environment,
Info: EnumBuildInfo<'ctx, Mode, E>,
+ Dynamic<Info::T>: DynBind<E>,
+ for<'a> Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>,
+ Dynamic<OwnedStatic<u32>>: DynBind<E>,
}
impl<'ctx, Info, Mode, E: Environment> Recoverable<'ctx, E> for EnumBuilder<'ctx, Info, Mode, E>
where
Info: EnumBuildInfo<'ctx, Mode, E>,
+ Dynamic<Info::T>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
@@ -183,16 +207,18 @@ impl<'ctx, Info, Mode, E: Environment> Value<'ctx, Info::ValueT, E>
for EnumBuilder<'ctx, Info, Mode, E>
where
Info: EnumBuildInfo<'ctx, Mode, E>,
+ Dynamic<Info::T>: DynBind<E>,
+ for<'a> Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>: DynBind<E>
{
fn visit<'a>(
&'a mut self,
value: TypeName::T<'a, 'ctx, Info::ValueT, E>,
- ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, Info::ValueT, E>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>>, E>
where
TypeName::T<'a, 'ctx, Info::ValueT, E>: Sized,
'ctx: 'a,
{
- self.inner = Inner::Value(Ok(Info::from_value(value)));
+ self.inner = Inner::Value(Ok(Dynamic(Info::from_value(value))));
E::value(Flow::Done.into()).cast()
}
}
@@ -201,6 +227,9 @@ impl<'ctx, Info, Mode, E: Environment> Tag<'ctx, tags::Variant, E>
for EnumBuilder<'ctx, Info, Mode, E>
where
Info: EnumBuildInfo<'ctx, Mode, E>,
+ Dynamic<Info::T>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>,
+ Dynamic<OwnedStatic<u32>>: DynBind<E>,
{
fn visit<'a: 'c, 'b: 'c, 'c>(
&'a mut self,
@@ -253,17 +282,20 @@ any_trait! {
where
E: Environment,
Info: EnumBuildInfo<'ctx, Mode, E>,
+ Dynamic<OwnedStatic<u32>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>,
}
impl<'ctx, Info, Mode, E: Environment> Value<'ctx, TempBorrowedStaticHrt<str>, E>
for VariantVisitor<'ctx, Info, Mode, E>
where
Info: EnumBuildInfo<'ctx, Mode, E>,
+ for<'a> Dynamic<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
TempBorrowedStatic(value): TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>,
- ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>>>, E>
where
TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>: Sized,
'ctx: 'a,
@@ -282,11 +314,13 @@ impl<'ctx, Info, Mode, E: Environment> Value<'ctx, OwnedStatic<u32>, E>
for VariantVisitor<'ctx, Info, Mode, E>
where
Info: EnumBuildInfo<'ctx, Mode, E>,
+ for<'a> Dynamic<TypeName::T<'a, 'ctx, OwnedStatic<u32>, E>>: DynBind<E>,
+ Dynamic<OwnedStatic<u32>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
OwnedStatic(value): TypeName::T<'a, 'ctx, OwnedStatic<u32>, E>,
- ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<u32>, E>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, OwnedStatic<u32>, E>>>, E>
where
TypeName::T<'a, 'ctx, OwnedStatic<u32>, E>: Sized,
'ctx: 'a,
diff --git a/src/build/builders/core/struct.rs b/src/build/builders/core/struct.rs
index f874fac..d08d06e 100644
--- a/src/build/builders/core/struct.rs
+++ b/src/build/builders/core/struct.rs
@@ -1,7 +1,7 @@
use core::fmt::{Debug, Display};
use effectful::{
- bound::{IsSend, IsSync},
+ bound::{IsSend, IsSync, Dynamic},
effective::Effective,
environment::{DynBind, Environment, NativeForm},
higher_ranked::Mut,
@@ -50,7 +50,7 @@ where
/// The kind of struct the builder is expecting.
kind: StructKind,
},
- Value(Info::T),
+ Value(Dynamic<Info::T>),
}
/// Structs are either tuple-like or map-like.
@@ -70,7 +70,8 @@ enum StructKind {
///
/// The `Mode` generic allows implementations to change depending on the mode the user gives.
/// It is not used by the trait directly.
-pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static {
+pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static
+{
/// A struct of builders for each field.
type Builders: DynBind<E>;
@@ -89,7 +90,7 @@ pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static {
type ValueT: TypeName::MemberType<E>;
/// The struct type this info is for.
- type T: DynBind<E>;
+ type T;
const FIELD_COUNT: usize;
@@ -99,7 +100,9 @@ pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static {
/// Finish building the struct value.
fn from_builders<'a>(
builders: Self::Builders,
- ) -> NativeForm<'a, Result<Self::T, Self::Error>, E>;
+ ) -> NativeForm<'a, Result<Dynamic<Self::T>, Self::Error>, E>
+ where
+ Dynamic<Self::T>: DynBind<E>;
/// Get the visitor for a field.
///
@@ -161,12 +164,19 @@ where
impl<'ctx, Info, Mode, E: Environment> BuilderTypes<E> for StructBuilder<'ctx, Info, Mode, E>
where
Info: StructTypeInfo<'ctx, Mode, E>,
+ Dynamic<Info::T>: DynBind<E>
{
type Seed = Info::Seed;
type Error = StructError<'ctx, Info, Mode, E>;
+ type Output = Dynamic<Info::T>;
+
type Value = Info::T;
+
+ fn unwrap_output(output: Self::Output) -> Self::Value {
+ output.0
+ }
}
impl<'ctx, Info, Mode: 'ctx, E: Environment> StructBuilder<'ctx, Info, Mode, E>
@@ -200,7 +210,14 @@ impl<'ctx, Info, Mode: 'ctx, E: Environment> Builder<'ctx, E> for StructBuilder<
where
Self: DynBind<E>,
Info: StructTypeInfo<'ctx, Mode, E>,
- for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>,
+ Dynamic<Info::T>: DynBind<E>,
+ Info: StructTypeInfo<'ctx, Mode, E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
+ for<'a> Dynamic<&'a Info::T>: DynBind<E>,
+ for<'b, 'c> Dynamic<TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>,
+ Dynamic<OwnedStatic<&'static str>>: DynBind<E>,
+ for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>,
+ for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>,
{
fn from_seed<'a>(seed: Self::Seed) -> NativeForm<'a, Self, E>
where
@@ -212,7 +229,7 @@ where
.cast()
}
- fn build<'a>(self) -> NativeForm<'a, Result<Self::Value, Self::Error>, E>
+ fn build<'a>(self) -> NativeForm<'a, Result<Self::Output, Self::Error>, E>
where
Self: 'a,
{
@@ -242,7 +259,14 @@ impl<'ctx, Info, Mode: 'ctx, E: Environment> AsVisitor<'ctx, E>
where
Self: DynBind<E>,
Info: StructTypeInfo<'ctx, Mode, E>,
- for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>,
+ Dynamic<Info::T>: DynBind<E>,
+ Info: StructTypeInfo<'ctx, Mode, E>,
+ Dynamic<OwnedStatic<&'static str>>: DynBind<E>,
+ for<'a> Dynamic<&'a Info::T>: DynBind<E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
+ for<'b, 'c> Dynamic<TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>,
+ for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>,
+ for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>,
{
fn as_visitor<'a>(&'a mut self) -> DynVisitor<'a, 'ctx, E>
where
@@ -260,10 +284,17 @@ any_trait! {
TagProto<tags::Map, E>,
SequenceProto<E>
] where
+ for<'a> Dynamic<&'a Info::T>: DynBind<E>,
E: Environment,
Self: DynBind<E>,
Info: StructTypeInfo<'ctx, Mode, E>,
- for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>,
+ Dynamic<Info::T>: DynBind<E>,
+ Dynamic<OwnedStatic<&'static str>>: DynBind<E>,
+ for<'b, 'c> Dynamic<TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>,
+ for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>,
+ for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
+ Dynamic<Info::T>: DynBind<E>,
Mode: 'ctx,
}
@@ -271,7 +302,13 @@ impl<'ctx, Info, Mode: 'ctx, E> RequestHint<'ctx, E> for StructBuilder<'ctx, Inf
where
Self: DynBind<E>,
Info: StructTypeInfo<'ctx, Mode, E>,
- for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>,
+ Dynamic<Info::T>: DynBind<E>,
+ for<'a> Dynamic<&'a Info::T>: DynBind<E>,
+ for<'b, 'c> Dynamic<TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>,
+ for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
+ for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>,
+ Dynamic<OwnedStatic<&'static str>>: DynBind<E>,
E: Environment,
{
#[inline(always)]
@@ -338,18 +375,18 @@ where
Self: DynBind<E>,
Info: StructTypeInfo<'ctx, Mode, E>,
E: Environment,
- for<'a> TypeName::T<'a, 'ctx, Info::ValueT, E>: DynBind<E>,
+ for<'a> Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
value: TypeName::T<'a, 'ctx, Info::ValueT, E>,
- ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, Info::ValueT, E>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>>, E>
where
TypeName::T<'a, 'ctx, Info::ValueT, E>: Sized,
'ctx: 'a,
{
// Get the value from what we got from the walker.
- self.inner = Inner::Value(Info::from_value(value));
+ self.inner = Inner::Value(Dynamic(Info::from_value(value)));
// Since we have the struct value we are done.
E::value(Flow::Done.into()).cast()
@@ -426,6 +463,9 @@ impl<'ctx, Info, Mode: 'ctx, E> Sequence<'ctx, E> for StructBuilder<'ctx, Info,
where
Self: DynBind<E>,
Info: StructTypeInfo<'ctx, Mode, E>,
+ for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>,
+ Dynamic<OwnedStatic<&'static str>>: DynBind<E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
E: Environment,
{
fn visit<'a: 'c, 'b: 'c, 'c>(
@@ -531,12 +571,18 @@ any_trait! {
} where
E: Environment,
I: StructTypeInfo<'ctx, M, E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
+ Dynamic<OwnedStatic<&'static str>>: DynBind<E>,
+ for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>,
}
impl<'d, 'ctx, I, M, E> Tag<'ctx, tags::Key, E> for FieldVisitor<'d, 'ctx, I, M, E>
where
E: Environment,
I: StructTypeInfo<'ctx, M, E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
+ Dynamic<OwnedStatic<&'static str>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>,
{
fn visit<'a: 'c, 'b: 'c, 'c>(
&'a mut self,
@@ -574,17 +620,21 @@ any_trait! {
] where
E: Environment,
I: StructTypeInfo<'ctx, M, E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
+ Dynamic<OwnedStatic<&'static str>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>,
}
impl<'ctx, I, M, E> Value<'ctx, OwnedStatic<usize>, E> for NameVisitor<'ctx, I, M, E>
where
E: Environment,
I: StructTypeInfo<'ctx, M, E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
OwnedStatic(index): TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>,
- ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>>>, E>
where
TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>: Sized,
'ctx: 'a,
@@ -599,11 +649,12 @@ impl<'ctx, I, M, E> Value<'ctx, TempBorrowedStaticHrt<str>, E> for NameVisitor<'
where
E: Environment,
I: StructTypeInfo<'ctx, M, E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
TempBorrowedStatic(name): TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>,
- ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>>>, E>
where
TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>: Sized,
'ctx: 'a,
@@ -618,11 +669,12 @@ impl<'ctx, I, M, E> Value<'ctx, OwnedStatic<&'static str>, E> for NameVisitor<'c
where
E: Environment,
I: StructTypeInfo<'ctx, M, E>,
+ Dynamic<OwnedStatic<&'static str>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
OwnedStatic(name): TypeName::T<'a, 'ctx, OwnedStatic<&'static str>, E>,
- ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<&'static str>, E>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, OwnedStatic<&'static str>, E>>>, E>
where
TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>: Sized,
'ctx: 'a,
diff --git a/src/build/builders/core/value.rs b/src/build/builders/core/value.rs
index 1109b51..55a0e99 100644
--- a/src/build/builders/core/value.rs
+++ b/src/build/builders/core/value.rs
@@ -5,6 +5,7 @@ use effectful::{
effective::Effective,
environment::{DynBind, Environment, NativeForm},
higher_ranked::Mut, SendSync,
+ bound::Dynamic,
};
use crate::{
@@ -53,27 +54,33 @@ pub enum NotCloneable {}
/// After
#[derive(SendSync)]
pub struct ValueBuilder<T, Clone, E> {
- value: Option<T>,
+ value: Option<Dynamic<T>>,
_marker: Marker<(E, Clone)>,
}
-impl<T, Clone, E: Environment> crate::BuilderTypes<E> for ValueBuilder<T, Clone, E>
+impl<T, Clone, E: Environment> crate::BuilderTypes<E> for ValueBuilder<T, Clone, E>
where
- T: DynBind<E>,
+ Dynamic<T>: DynBind<E>
{
type Error = ValueError<T>;
+ type Output = Dynamic<T>;
+
type Value = T;
type Seed = ();
+
+ fn unwrap_output(output: Self::Output) -> Self::Value {
+ output.0
+ }
}
impl<'ctx, T: 'static, Clone, E: Environment> crate::Builder<'ctx, E> for ValueBuilder<T, Clone, E>
where
+ Dynamic<T>: DynBind<E>,
Self: AnyTrait<'ctx, E>,
- T: DynBind<E>,
{
- fn build<'a>(self) -> NativeForm<'a, Result<Self::Value, Self::Error>, E>
+ fn build<'a>(self) -> NativeForm<'a, Result<Self::Output, Self::Error>, E>
where
Self: 'a,
{
@@ -110,7 +117,11 @@ any_trait! {
ValueProto<OwnedStatic<T>, E>,
] where
E: Environment,
- T: DynBind<E> + IsSync<E::NeedSend> + 'static
+ T: 'static,
+ Dynamic<T>: DynBind<E>,
+ for<'a> Dynamic<&'a T>: DynBind<E>,
+ Dynamic<OwnedStatic<T>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<T>>: DynBind<E>,
}
any_trait! {
@@ -123,12 +134,27 @@ any_trait! {
ValueProto<TempBorrowedMutStaticHrt<T>, E>,
] where
E: Environment,
- T: DynBind<E> + IsSync<E::NeedSend> + 'static + Clone,
+ T: 'static + Clone,
+ Dynamic<T>: DynBind<E>,
+ for<'a> Dynamic<&'a T>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<T>>: DynBind<E>,
+ Dynamic<OwnedStatic<T>>: DynBind<E>,
+ Dynamic<BorrowedStatic<'ctx, T>>: DynBind<E>,
+ for<'a, 'b> Dynamic<&'a BorrowedStatic<'b, T>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, T>>: DynBind<E>,
+ for<'a> Dynamic<&'a TempBorrowedStatic<'a, T>>: DynBind<E>,
+ Dynamic<BorrowedMutStatic<'ctx, T>>: DynBind<E>,
+ for<'a, 'b> Dynamic<&'a BorrowedMutStatic<'b, T>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedMutStatic<'a, T>>: DynBind<E>,
+ for<'a> Dynamic<&'a TempBorrowedMutStatic<'a, T>>: DynBind<E>,
}
impl<'ctx, T: 'static, E: Environment> RequestHint<'ctx, E> for ValueBuilder<T, NotCloneable, E>
where
- T: DynBind<E> + IsSync<E::NeedSend>,
+ Dynamic<T>: DynBind<E>,
+ for<'a> Dynamic<&'a T>: DynBind<E>,
+ Dynamic<OwnedStatic<T>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<T>>: DynBind<E>,
{
fn request_hint<'this: 'e, 'walker: 'e, 'e>(
&'this mut self,
@@ -147,7 +173,19 @@ where
impl<'ctx, T: 'static, E: Environment> RequestHint<'ctx, E> for ValueBuilder<T, Cloneable, E>
where
- T: DynBind<E> + IsSync<E::NeedSend> + Clone,
+ T: Clone,
+ Dynamic<T>: DynBind<E>,
+ for<'a> Dynamic<&'a T>: DynBind<E>,
+ Dynamic<OwnedStatic<T>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<T>>: DynBind<E>,
+ Dynamic<BorrowedStatic<'ctx, T>>: DynBind<E>,
+ for<'a, 'b> Dynamic<&'a BorrowedStatic<'b, T>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, T>>: DynBind<E>,
+ for<'a> Dynamic<&'a TempBorrowedStatic<'a, T>>: DynBind<E>,
+ Dynamic<BorrowedMutStatic<'ctx, T>>: DynBind<E>,
+ for<'a, 'b> Dynamic<&'a BorrowedMutStatic<'b, T>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedMutStatic<'a, T>>: DynBind<E>,
+ for<'a> Dynamic<&'a TempBorrowedMutStatic<'a, T>>: DynBind<E>,
{
fn request_hint<'this: 'e, 'walker: 'e, 'e>(
&'this mut self,
@@ -196,16 +234,17 @@ where
impl<'ctx, T: 'static, Clone, E: Environment> Value<'ctx, OwnedStatic<T>, E>
for ValueBuilder<T, Clone, E>
where
- T: DynBind<E>,
+ Dynamic<T>: DynBind<E>,
+ Dynamic<OwnedStatic<T>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
OwnedStatic(value): OwnedStatic<T>,
- ) -> NativeForm<'a, VisitResult<OwnedStatic<T>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<OwnedStatic<T>>>, E>
where
'ctx: 'a,
{
- self.value = Some(value);
+ self.value = Some(Dynamic(value));
E::value(Flow::Done.into()).cast()
}
@@ -214,16 +253,18 @@ where
impl<'ctx, T: 'static, E: Environment> Value<'ctx, BorrowedStaticHrt<T>, E>
for ValueBuilder<T, Cloneable, E>
where
- T: Clone + DynBind<E> + IsSync<E::NeedSend>,
+ T: Clone,
+ Dynamic<T>: DynBind<E>,
+ Dynamic<BorrowedStatic<'ctx, T>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
BorrowedStatic(value): BorrowedStatic<'ctx, T>,
- ) -> NativeForm<'a, VisitResult<BorrowedStatic<'ctx, T>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<BorrowedStatic<'ctx, T>>>, E>
where
'ctx: 'a,
{
- self.value = Some(value.clone());
+ self.value = Some(Dynamic(value.clone()));
E::value(Flow::Done.into()).cast()
}
@@ -232,16 +273,18 @@ where
impl<'ctx, T: 'static, E: Environment> Value<'ctx, TempBorrowedStaticHrt<T>, E>
for ValueBuilder<T, Cloneable, E>
where
- T: Clone + DynBind<E> + IsSync<E::NeedSend>,
+ T: Clone,
+ Dynamic<T>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, T>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
TempBorrowedStatic(value): TempBorrowedStatic<'a, T>,
- ) -> NativeForm<'a, VisitResult<TempBorrowedStatic<'a, T>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TempBorrowedStatic<'a, T>>>, E>
where
'ctx: 'a,
{
- self.value = Some(value.clone());
+ self.value = Some(Dynamic(value.clone()));
E::value(Flow::Done.into()).cast()
}
@@ -250,16 +293,18 @@ where
impl<'ctx, T: 'static, E: Environment> Value<'ctx, BorrowedMutStaticHrt<T>, E>
for ValueBuilder<T, Cloneable, E>
where
- T: Clone + DynBind<E> + IsSync<E::NeedSend>,
+ T: Clone,
+ Dynamic<T>: DynBind<E>,
+ Dynamic<BorrowedMutStatic<'ctx, T>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
BorrowedMutStatic(value): BorrowedMutStatic<'ctx, T>,
- ) -> NativeForm<'a, VisitResult<BorrowedMutStatic<'ctx, T>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<BorrowedMutStatic<'ctx, T>>>, E>
where
'ctx: 'a,
{
- self.value = Some(value.clone());
+ self.value = Some(Dynamic(value.clone()));
E::value(Flow::Done.into()).cast()
}
@@ -268,16 +313,18 @@ where
impl<'ctx, T: 'static, E: Environment> Value<'ctx, TempBorrowedMutStaticHrt<T>, E>
for ValueBuilder<T, Cloneable, E>
where
- T: Clone + DynBind<E> + IsSync<E::NeedSend>,
+ T: Clone,
+ Dynamic<T>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedMutStatic<'a, T>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
TempBorrowedMutStatic(value): TempBorrowedMutStatic<'a, T>,
- ) -> NativeForm<'a, VisitResult<TempBorrowedMutStatic<'a, T>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TempBorrowedMutStatic<'a, T>>>, E>
where
'ctx: 'a,
{
- self.value = Some(value.clone());
+ self.value = Some(Dynamic(value.clone()));
E::value(Flow::Done.into()).cast()
}
diff --git a/src/macros/build.rs b/src/macros/build.rs
index c77426d..14e4443 100644
--- a/src/macros/build.rs
+++ b/src/macros/build.rs
@@ -9,20 +9,23 @@ macro_rules! Build {
#[allow(non_upper_case_globals, non_snake_case, non_camel_case_types)]
const _: () = {
// add a module here to seal fields.
- impl<'ctx, M: 'ctx, E: effectful::environment::Environment> $crate::Build<'ctx, M, E> for $name
+ impl<'ctx, M: 'ctx, E: effectful::environment::Environment> $crate::Build<'ctx, M, E> for $name
where
- $name: effectful::environment::DynBind<E> + effectful::bound::IsSync<E::NeedSend>
+ effectful::bound::Dynamic<$name>: effectful::environment::DynBind<E>,
+ $($type: $crate::Build<'ctx, M, E>,)*
+ $crate::builders::core::r#struct::StructBuilder<'ctx, __Info, M, E>: $crate::Builder<'ctx, E, Value = Self>
{
type Builder = $crate::builders::core::r#struct::StructBuilder<'ctx, __Info, M, E>;
}
- $vis struct Builders<'ctx, M: 'ctx, E: effectful::environment::Environment> {
+ #[derive(SendSync)]
+ $vis struct Builders<'ctx, M: 'ctx, E: effectful::environment::Environment>
+ where
+ $($type: $crate::Build<'ctx, M, E>),*
+ {
$($field: <$type as $crate::Build<'ctx, M, E>>::Builder),*
}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSend<E::NeedSend> for Builders<'ctx, M, E> {}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSync<E::NeedSync> for Builders<'ctx, M, E> {}
-
#[derive(Copy, Clone, Debug, SendSync)]
$vis enum Field {
$($field),*
@@ -36,13 +39,14 @@ macro_rules! Build {
$(pub const $field: usize = __Fields::$field as usize;)*
}
- $vis enum Error<'ctx, M: 'ctx, E: effectful::environment::Environment> {
+ #[derive(SendSync)]
+ $vis enum Error<'ctx, M: 'ctx, E: effectful::environment::Environment>
+ where
+ $($type: $crate::Build<'ctx, M, E>),*
+ {
$($field(<<$type as $crate::Build<'ctx, M, E>>::Builder as $crate::BuilderTypes<E>>::Error)),*
}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSend<E::NeedSend> for Error<'ctx, M, E> {}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSync<E::NeedSync> for Error<'ctx, M, E> {}
-
impl ::core::fmt::Display for Field {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.write_str(match self {
@@ -51,7 +55,10 @@ macro_rules! Build {
}
}
- impl<'ctx, M: 'ctx, E: effectful::environment::Environment> ::core::fmt::Debug for Error<'ctx, M, E> {
+ impl<'ctx, M: 'ctx, E: effectful::environment::Environment> ::core::fmt::Debug for Error<'ctx, M, E>
+ where
+ $($type: $crate::Build<'ctx, M, E>),*
+ {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.write_str(match self {
$(Error::$field(_) => stringify!($field)),*
@@ -59,7 +66,10 @@ macro_rules! Build {
}
}
- impl<'ctx, M: 'ctx, E: effectful::environment::Environment> ::core::fmt::Display for Error<'ctx, M, E> {
+ impl<'ctx, M: 'ctx, E: effectful::environment::Environment> ::core::fmt::Display for Error<'ctx, M, E>
+ where
+ $($type: $crate::Build<'ctx, M, E>),*
+ {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.write_str(match self {
$(Error::$field(_) => stringify!($field)),*
@@ -67,18 +77,20 @@ macro_rules! Build {
}
}
+ #[derive(SendSync)]
$vis struct __Info;
- impl<'ctx, M: 'ctx, E: effectful::environment::Environment> $crate::builders::core::r#struct::StructTypeInfo<'ctx, M, E> for __Info
+ impl<'ctx, M: 'ctx, E: effectful::environment::Environment> $crate::builders::core::r#struct::StructTypeInfo<'ctx, M, E> for __Info
where
- $name: effectful::environment::DynBind<E>
+ effectful::bound::Dynamic<$name>: effectful::environment::DynBind<E>,
+ $($type: $crate::Build<'ctx, M, E>),*
{
type Builders = Builders<'ctx, M, E>;
type FieldMarker = Field;
type T = $name;
type Error = Error<'ctx, M, E>;
type Seed = ($(<<$type as $crate::Build<'ctx, M, E>>::Builder as $crate::BuilderTypes<E>>::Seed),*);
- type ValueT = $crate::any::OwnedStatic<$name>;
+ type ValueT = $crate::any::OwnedStatic<effectful::bound::Dynamic<$name>>;
const FIELD_COUNT: usize = {
[$(stringify!($field)),*].len()
@@ -99,7 +111,7 @@ macro_rules! Build {
// })
}
- fn from_builders<'a>(builders: Self::Builders) -> effectful::environment::NativeForm<'a, Result<Self::T, Self::Error>, E> {
+ fn from_builders<'a>(builders: Self::Builders) -> effectful::environment::NativeForm<'a, Result<effectful::bound::Dynamic<Self::T>, Self::Error>, E> {
use $crate::Builder;
todo!()
@@ -142,7 +154,7 @@ macro_rules! Build {
}
fn from_value(value: Self::ValueT) -> Self::T {
- value.0
+ value.0.0
}
}
};
@@ -156,27 +168,32 @@ macro_rules! Build {
#[allow(non_upper_case_globals, non_snake_case, non_camel_case_types)]
const _: () = {
// add a module here to seal fields.
- impl<'ctx, M: 'ctx, E: effectful::environment::Environment> $crate::Build<'ctx, M, E> for $name {
+ impl<'ctx, M: 'ctx, E: effectful::environment::Environment> $crate::Build<'ctx, M, E> for $name
+ where
+ effectful::bound::Dynamic<$name>: effectful::environment::DynBind<E>,
+ $($value: $crate::Build<'ctx, M, E>,)*
+ $(<<$value as Build<'ctx, M, E>>::Builder as BuilderTypes<E>>::Seed: Default,)*
+ $crate::builders::core::r#enum::EnumBuilder<'ctx, __Info, M, E>: $crate::Builder<'ctx, E, Value = Self>
+ {
type Builder = $crate::builders::core::r#enum::EnumBuilder<'ctx, __Info, M, E>;
}
+ #[derive(SendSync)]
$vis struct __Info;
- $vis enum __Builders<'ctx, M, E: effectful::environment::Environment> {
+ #[derive(SendSync)]
+ $vis enum __Builders<'ctx, M, E: effectful::environment::Environment>
+ where
+ $($value: $crate::Build<'ctx, M, E>),*
+ {
$($variant(<$value as $crate::Build<'ctx, M, E>>::Builder)),*
}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSend<E::NeedSend> for __Builders<'ctx, M, E> {}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSync<E::NeedSync> for __Builders<'ctx, M, E> {}
-
- #[derive(Copy, Clone)]
+ #[derive(Copy, Clone, SendSync)]
$vis enum __Marker {
$($variant),*
}
- unsafe impl<'ctx, F: effectful::bound::Bool> effectful::bound::IsSend<F> for __Marker {}
- unsafe impl<'ctx, F: effectful::bound::Bool> effectful::bound::IsSync<F> for __Marker {}
-
impl ::core::fmt::Display for __Marker {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.write_str(match self {
@@ -193,24 +210,29 @@ macro_rules! Build {
$(pub const $variant: u32 = __Variants::$variant as u32;)*
}
- $vis struct __ErrorBuilder<'ctx, M, E: Environment> {
+ #[derive(SendSync)]
+ $vis struct __ErrorBuilder<'ctx, M, E: Environment>
+ where
+ $($value: $crate::Build<'ctx, M, E>),*
+ {
$($variant: Option<<<$value as $crate::Build<'ctx, M, E>>::Builder as BuilderTypes<E>>::Error>),*
}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSend<E::NeedSend> for __ErrorBuilder<'ctx, M, E> {}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSync<E::NeedSync> for __ErrorBuilder<'ctx, M, E> {}
-
- $vis enum __Error<'ctx, M, E: Environment> {
+ #[derive(SendSync)]
+ $vis enum __Error<'ctx, M, E: Environment>
+ where
+ $($value: $crate::Build<'ctx, M, E>),*
+ {
__Guess {
$($variant: <<$value as $crate::Build<'ctx, M, E>>::Builder as BuilderTypes<E>>::Error),*
},
$($variant(<<$value as $crate::Build<'ctx, M, E>>::Builder as BuilderTypes<E>>::Error)),*
}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSend<E::NeedSend> for __Error<'ctx, M, E> {}
- unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSync<E::NeedSync> for __Error<'ctx, M, E> {}
-
- impl<'ctx, M, E: Environment> ::core::fmt::Display for __Error<'ctx, M, E> {
+ impl<'ctx, M, E: Environment> ::core::fmt::Display for __Error<'ctx, M, E>
+ where
+ $($value: $crate::Build<'ctx, M, E>),*
+ {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
match self {
Self::__Guess {
@@ -225,7 +247,10 @@ macro_rules! Build {
}
}
- impl<'ctx, M, E: Environment> ::core::fmt::Debug for __Error<'ctx, M, E> {
+ impl<'ctx, M, E: Environment> ::core::fmt::Debug for __Error<'ctx, M, E>
+ where
+ $($value: $crate::Build<'ctx, M, E>),*
+ {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
match self {
Self::__Guess {
@@ -240,7 +265,12 @@ macro_rules! Build {
}
}
- impl<'ctx, M: 'ctx, E: effectful::environment::Environment> $crate::builders::core::r#enum::EnumBuildInfo<'ctx, M, E> for __Info {
+ impl<'ctx, M: 'ctx, E: effectful::environment::Environment> $crate::builders::core::r#enum::EnumBuildInfo<'ctx, M, E> for __Info
+ where
+ effectful::bound::Dynamic<$name>: effectful::environment::DynBind<E>,
+ $($value: $crate::Build<'ctx, M, E>,)*
+ $(<<$value as Build<'ctx, M, E>>::Builder as BuilderTypes<E>>::Seed: Default),*
+ {
type Builders = __Builders<'ctx, M, E>;
type Seed = ();
@@ -266,9 +296,9 @@ macro_rules! Build {
fn finish_builder<'a>(
builder: Self::Builders,
- ) -> NativeForm<'a, Result<Self::T, Self::Error>, E> {
+ ) -> NativeForm<'a, Result<effectful::bound::Dynamic<Self::T>, Self::Error>, E> {
match builder {
- $(__Builders::$variant(builder) => builder.build().map((), |_, value| value.map($name::$variant).map_err(__Error::$variant)).cast()),*
+ $(__Builders::$variant(builder) => builder.build().map((), |_, value| value.map(|x| effectful::bound::Dynamic($name::$variant(<<$value as Build<'ctx, M, E>>::Builder as BuilderTypes<E>>::unwrap_output(x)))).map_err(__Error::$variant)).cast()),*
}
}
@@ -299,20 +329,22 @@ macro_rules! Build {
fn guess_variant<'a>(
seed: Self::Seed,
scope: DynRecoverableScope<'a, 'ctx, E>,
- ) -> NativeForm<'a, Result<Self::T, Self::Error>, E> {
+ ) -> NativeForm<'a, Result<effectful::bound::Dynamic<Self::T>, Self::Error>, E> {
use effectful::effective::EffectiveExt;
use effectful::short::ResultErrorExt;
E::value((scope, Err(__ErrorBuilder::<M, E> { A: None, B: None })))
$(.or_else_update((), |_, scope, result| {
let mut error = result.into_error();
-
+
<<$value as Build<M, E>>::Builder as Builder<_>>::from_seed(Default::default())
.map(scope, |scope, builder| (scope, builder))
.update((), |(), (scope, builder)| scope.new_walk(builder.as_visitor()).cast())
.then((), |(), ((_, builder), _)| builder.build())
.map(error, |mut error, result| {
- result.map(X::$variant).map_err(|err| {
+ result.map(|x| effectful::bound::Dynamic(X::$variant(
+ <<$value as Build<'ctx, M, E>>::Builder as BuilderTypes<E>>::unwrap_output(x)
+ ))).map_err(|err| {
error.$variant = Some(err);
error
})
diff --git a/src/protocol/visitor/request_hint.rs b/src/protocol/visitor/request_hint.rs
index 76de7a0..183014f 100644
--- a/src/protocol/visitor/request_hint.rs
+++ b/src/protocol/visitor/request_hint.rs
@@ -56,21 +56,19 @@ pub fn request_hint<'ctx: 'visitor + 'walker, 'visitor: 'e, 'walker: 'e, 'e, E:
visitor: DynVisitor<'visitor, 'ctx, E>,
walker: DynWalker<'walker, 'ctx, E>,
) -> NativeForm<'e, VisitResult<DynWalker<'walker, 'ctx, E>>, E> {
- E::value(walker)
- .update(visitor, |visitor, walker| {
+ E::value((visitor, walker))
+ .update((), |_, (visitor, walker)| {
if let Some(object) = visitor.0.upcast_mut::<RequestHintProto<E>>() {
// Allow the visitor to give a hint if it wants.
object
.request_hint(walker.cast())
.map((), |_, x| x.unit_skipped())
- .cast::<()>();
-
- todo!()
+ .cast()
} else {
// If the visitor doesn't support request hint then we continue.
E::value(VisitResult::Skipped(())).cast()
}
})
- .map((), |_, (walker, result)| result.map_skipped(|_| walker))
+ .map((), |_, ((_, walker), result)| result.map_skipped(|_| walker))
.cast()
}
diff --git a/src/protocol/visitor/value.rs b/src/protocol/visitor/value.rs
index 5a6e7c2..6efd1c5 100644
--- a/src/protocol/visitor/value.rs
+++ b/src/protocol/visitor/value.rs
@@ -3,7 +3,7 @@
//! In some sense, this is the most basic protocol.
use effectful::{
- bound::{Bool, IsSend, IsSync},
+ bound::{Bool, IsSend, IsSync, Dynamic},
effective::Effective,
environment::{DynBind, EnvConfig, Environment, NativeForm}, SendSync,
};
@@ -35,8 +35,9 @@ pub trait Value<'ctx, T: ?Sized + TypeName::MemberType<E>, E: Environment>: DynB
fn visit<'a>(
&'a mut self,
value: TypeName::T<'a, 'ctx, T, E>,
- ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, T, E>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, T, E>>>, E>
where
+ Dynamic<TypeName::T<'a, 'ctx, T, E>>: DynBind<E>,
TypeName::T<'a, 'ctx, T, E>: Sized,
'ctx: 'a;
}
@@ -67,7 +68,7 @@ pub struct ValueKnown<'a, T: ?Sized> {
/// A preview of the value.
///
/// This can be used to inspect the value before committing to a visit.
- pub preview: Option<&'a T>,
+ pub preview: Option<Dynamic<&'a T>>,
}
#[derive(Copy, Clone, Debug, SendSync)]
@@ -77,7 +78,7 @@ impl<'a, 'ctx, E: EnvConfig, T> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>
for ValueKnownHrt<T>
where
T: ?Sized + TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>,
- TypeName::T<'a, 'ctx, T, E>: IsSync<E::NeedSend>,
+ Dynamic<&'a TypeName::T<'a, 'ctx, T, E>>: DynBind<E>,
{
type T = ValueKnown<'a, TypeName::T<'a, 'ctx, T, E>>;
}
@@ -86,7 +87,7 @@ impl<'a, 'ctx, E: EnvConfig, T: ?Sized> Meta::LowerTypeWithBound<'a, 'ctx, E, &'
for ValueKnown<'a, T>
where
T: TypeName::LowerType<'a, 'ctx, E>,
- T: IsSync<E::NeedSend>,
+ Dynamic<&'a T>: DynBind<E>,
{
type Higher = ValueKnownHrt<TypeName::HigherRanked<'a, 'ctx, T, E>>;
}
@@ -94,7 +95,7 @@ where
// This enrolls the Value protocol into the walker hint system.
impl<T: TypeName::MemberType<E>, E: Environment> HintMeta for ValueProto<T, E>
where
- for<'a, 'ctx> TypeName::T<'a, 'ctx, T, E>: IsSync<E::NeedSend>,
+ for<'a, 'ctx> Dynamic<&'a TypeName::T<'a, 'ctx, T, E>>: DynBind<E>,
{
type Known = ValueKnownHrt<T>;
@@ -112,9 +113,10 @@ pub fn visit_value<
>(
visitor: DynVisitor<'visitor, 'ctx, E>,
value: T,
-) -> NativeForm<'e, VisitResult<T>, E>
+) -> NativeForm<'e, VisitResult<Dynamic<T>>, E>
where
TypeName::HigherRanked<'e, 'ctx, T, E>: TypeName::MemberType<E>,
+ Dynamic<T>: DynBind<E>
{
if let Some(object) = visitor
.0
@@ -124,7 +126,7 @@ where
object.visit(value)
} else {
// If the visitor doesn't support request hint then we continue.
- E::value(VisitResult::Skipped(value)).cast()
+ E::value(VisitResult::Skipped(Dynamic(value))).cast()
}
}
diff --git a/src/transform.rs b/src/transform.rs
index 2f57a90..2bbc2c6 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -22,7 +22,7 @@ pub fn transform<
>(
seed: B::Seed,
walker: W,
-) -> NativeForm<'a, (Result<B::Value, B::Error>, Result<W::Output, W::Error>), E> {
+) -> NativeForm<'a, (Result<B::Output, B::Error>, Result<W::Output, W::Error>), E> {
B::from_seed(seed)
.update(walker, |walker, builder| {
walker.walk(builder.as_visitor()).cast()
@@ -86,7 +86,7 @@ pub trait BuildExt {
W: Walker<'ctx, Blocking<Cfg<Spin, No, No>>>,
{
match transform::<Self::Builder, _, _>(Default::default(), walker).into_value() {
- (Ok(value), _) => Ok(value),
+ (Ok(value), _) => Ok(Self::Builder::unwrap_output(value)),
(Err(err), Ok(_)) => Err(BuildError::Builder(err)),
(Err(build_err), Err(walker_err)) => Err(BuildError::Both(build_err, walker_err)),
}
@@ -116,7 +116,7 @@ pub trait BuildExt {
.into_future()
.await
{
- (Ok(value), _) => Ok(value),
+ (Ok(value), _) => Ok(Self::Builder::unwrap_output(value)),
(Err(err), Ok(_)) => Err(BuildError::Builder(err)),
(Err(build_err), Err(walker_err)) => Err(BuildError::Both(build_err, walker_err)),
}
@@ -164,7 +164,7 @@ pub trait WalkExt {
.into_value()
.walk(builder.as_visitor());
match builder.build().into_value() {
- Ok(value) => Ok(value),
+ Ok(value) => Ok(B::unwrap_output(value)),
_ => todo!(),
}
}
diff --git a/src/walk/walkers.rs b/src/walk/walkers.rs
index b5d0e43..f5eac87 100644
--- a/src/walk/walkers.rs
+++ b/src/walk/walkers.rs
@@ -1,4 +1,4 @@
pub mod core;
-// #[cfg(feature = "serde")]
-// pub mod serde;
+#[cfg(feature = "serde")]
+pub mod serde;
diff --git a/src/walk/walkers/core/bool.rs b/src/walk/walkers/core/bool.rs
index c6e7652..5189ecc 100644
--- a/src/walk/walkers/core/bool.rs
+++ b/src/walk/walkers/core/bool.rs
@@ -1,13 +1,16 @@
use effectful::{
- effective::Effective,
- environment::{Environment, NativeForm},
+ bound::Dynamic, effective::Effective, environment::{DynBind, Environment, NativeForm}
};
-use crate::Walk;
+use crate::{any::OwnedStatic, Walk};
use super::value::ValueWalker;
-impl<'ctx, M, E: Environment> Walk<'ctx, M, E> for bool {
+impl<'ctx, M, E: Environment> Walk<'ctx, M, E> for bool
+where
+ Dynamic<bool>: DynBind<E>,
+ Dynamic<OwnedStatic<bool>>: DynBind<E>,
+{
type Walker = ValueWalker<bool>;
fn into_walker<'e>(self) -> NativeForm<'e, Self::Walker, E> {
@@ -15,7 +18,11 @@ impl<'ctx, M, E: Environment> Walk<'ctx, M, E> for bool {
}
}
-impl<'ctx, M, E: Environment> Walk<'ctx, M, E> for &'ctx bool {
+impl<'ctx, M, E: Environment> Walk<'ctx, M, E> for &'ctx bool
+where
+ Dynamic<bool>: DynBind<E>,
+ Dynamic<OwnedStatic<bool>>: DynBind<E>,
+{
type Walker = ValueWalker<bool>;
fn into_walker<'e>(self) -> NativeForm<'e, Self::Walker, E> {
diff --git a/src/walk/walkers/core/int.rs b/src/walk/walkers/core/int.rs
index bf6b8c8..4d66dfc 100644
--- a/src/walk/walkers/core/int.rs
+++ b/src/walk/walkers/core/int.rs
@@ -1,6 +1,7 @@
use effectful::effective::Effective;
use effectful::environment::{DynBind, Environment, NativeForm};
use effectful::higher_ranked::Mut;
+use effectful::bound::Dynamic;
use effectful::SendSync;
use crate::{
@@ -20,7 +21,7 @@ use crate::{
#[derive(SendSync)]
pub struct IntegerWalker<T, E> {
- value: T,
+ value: Dynamic<T>,
_marker: Marker<E>,
}
@@ -48,10 +49,10 @@ fn try_into<T: TryInto<U>, U>(value: T) -> Option<U> {
value.try_into().ok()
}
-impl<'ctx, T, E> IntegerWalker<T, E> {
+impl<T, E> IntegerWalker<T, E> {
pub fn new(value: T) -> Self {
Self {
- value,
+ value: Dynamic(value),
_marker: Default::default(),
}
}
@@ -59,7 +60,7 @@ impl<'ctx, T, E> IntegerWalker<T, E> {
#[derive(SendSync)]
pub struct IntegerWalkerError<T> {
- value: T,
+ value: Dynamic<T>,
}
impl<T: Integer> ::core::fmt::Debug for IntegerWalkerError<T> {
@@ -80,11 +81,35 @@ impl<T: Integer> ::core::fmt::Display for IntegerWalkerError<T> {
impl<'ctx, T: Integer, E: Environment> Walker<'ctx, E> for IntegerWalker<T, E>
where
- T: DynBind<E>,
+ Dynamic<T>: DynBind<E>,
+ Dynamic<OwnedStatic<i8>>: DynBind<E>,
+ Dynamic<OwnedStatic<i16>>: DynBind<E>,
+ Dynamic<OwnedStatic<i32>>: DynBind<E>,
+ Dynamic<OwnedStatic<i64>>: DynBind<E>,
+ Dynamic<OwnedStatic<i128>>: DynBind<E>,
+ Dynamic<OwnedStatic<isize>>: DynBind<E>,
+ Dynamic<OwnedStatic<u8>>: DynBind<E>,
+ Dynamic<OwnedStatic<u16>>: DynBind<E>,
+ Dynamic<OwnedStatic<u32>>: DynBind<E>,
+ Dynamic<OwnedStatic<u64>>: DynBind<E>,
+ Dynamic<OwnedStatic<u128>>: DynBind<E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i8>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i16>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i32>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i64>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i128>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<isize>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u8>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u16>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u32>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u64>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u128>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<usize>>: DynBind<E>,
{
type Error = IntegerWalkerError<T>;
- type Output = T;
+ type Output = Dynamic<T>;
fn walk<'visitor: 'effect, 'effect>(
self,
@@ -104,7 +129,7 @@ where
.map((), |_, ((_, visitor), result)| (visitor, result))
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, i8>(value) {
+ if let Some(value) = try_into::<_, i8>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -114,7 +139,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, u8>(value) {
+ if let Some(value) = try_into::<_, u8>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -124,7 +149,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, i16>(value) {
+ if let Some(value) = try_into::<_, i16>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -134,7 +159,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, u16>(value) {
+ if let Some(value) = try_into::<_, u16>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -144,7 +169,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, i32>(value) {
+ if let Some(value) = try_into::<_, i32>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -154,7 +179,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, u32>(value) {
+ if let Some(value) = try_into::<_, u32>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -164,7 +189,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, i64>(value) {
+ if let Some(value) = try_into::<_, i64>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -174,7 +199,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, u64>(value) {
+ if let Some(value) = try_into::<_, u64>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -184,7 +209,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, i128>(value) {
+ if let Some(value) = try_into::<_, i128>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -194,7 +219,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, u128>(value) {
+ if let Some(value) = try_into::<_, u128>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -204,7 +229,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, isize>(value) {
+ if let Some(value) = try_into::<_, isize>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -214,7 +239,7 @@ where
})
.cast::<()>()
.if_skipped(value, |value, visitor| {
- if let Some(value) = try_into::<_, usize>(value) {
+ if let Some(value) = try_into::<_, usize>(value.0) {
visit_value::<_, E>(visitor.cast(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
@@ -263,8 +288,33 @@ any_trait! {
HintProto<ValueProto<OwnedStatic<u64>, E>>,
HintProto<ValueProto<OwnedStatic<u128>, E>>,
] where
- T: DynBind<E> + Integer,
- E: Environment
+ T: Integer,
+ E: Environment,
+ Dynamic<T>: DynBind<E>,
+ Dynamic<OwnedStatic<i8>>: DynBind<E>,
+ Dynamic<OwnedStatic<i16>>: DynBind<E>,
+ Dynamic<OwnedStatic<i32>>: DynBind<E>,
+ Dynamic<OwnedStatic<i64>>: DynBind<E>,
+ Dynamic<OwnedStatic<i128>>: DynBind<E>,
+ Dynamic<OwnedStatic<isize>>: DynBind<E>,
+ Dynamic<OwnedStatic<u8>>: DynBind<E>,
+ Dynamic<OwnedStatic<u16>>: DynBind<E>,
+ Dynamic<OwnedStatic<u32>>: DynBind<E>,
+ Dynamic<OwnedStatic<u64>>: DynBind<E>,
+ Dynamic<OwnedStatic<u128>>: DynBind<E>,
+ Dynamic<OwnedStatic<usize>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i8>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i16>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i32>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i64>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<i128>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<isize>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u8>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u16>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u32>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u64>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<u128>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<usize>>: DynBind<E>,
}
macro_rules! impl_hints {
@@ -272,7 +322,9 @@ macro_rules! impl_hints {
$(impl<'ctx, T: Integer, E: Environment> Hint<'ctx, ValueProto<OwnedStatic<$type>, E>>
for IntegerWalker<T, E>
where
- T: DynBind<E>,
+ Dynamic<T>: DynBind<E>,
+ Dynamic<OwnedStatic<$type>>: DynBind<E>,
+ for<'a> Dynamic<&'a OwnedStatic<$type>>: DynBind<E>
{
fn hint<'this: 'e, 'visitor: 'e, 'hint: 'e, 'e>(
&'this mut self,
@@ -282,7 +334,7 @@ macro_rules! impl_hints {
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
- if let Some(value) = try_into::<_, $type>(self.value) {
+ if let Some(value) = try_into::<_, $type>(self.value.0) {
visit_value::<_, E>(visitor.into_inner(), OwnedStatic(value))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
diff --git a/src/walk/walkers/core/struct.rs b/src/walk/walkers/core/struct.rs
index c4a9d49..561a464 100644
--- a/src/walk/walkers/core/struct.rs
+++ b/src/walk/walkers/core/struct.rs
@@ -1,13 +1,13 @@
use core::any::TypeId;
use effectful::{
- bound::{IsSend, IsSync},
+ bound::{IsSend, IsSync, Dynamic},
effective::Effective,
environment::{DynBind, Environment, NativeForm}, SendSync,
};
use crate::{
- any::{AnyTrait, BorrowedStatic, BorrowedStaticHrt, StaticType},
+ any::{AnyTrait, BorrowedStatic, BorrowedStaticHrt, StaticType, OwnedStatic},
any_trait,
hkt::Marker,
never::Never,
@@ -33,7 +33,7 @@ use super::{noop::NoopWalker, value::ValueWalker};
#[derive(SendSync)]
pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Environment> {
/// Struct value to walk.
- value: &'ctx I::T,
+ value: Dynamic<&'ctx I::T>,
/// Index of the current field to walk.
index: usize,
@@ -101,7 +101,7 @@ where
/// Create walker from a borrow of a struct.
pub fn new(value: &'ctx I::T) -> Self {
Self {
- value,
+ value: Dynamic(value),
index: 0,
error: None,
_generics: Default::default(),
@@ -178,7 +178,12 @@ any_trait! {
E: Environment,
I: StructTypeInfo<'ctx, M, E, S = StaticType>,
M: 'ctx,
- I::T: IsSync<E::NeedSend> + 'static
+ I::T: 'static,
+ Dynamic<&'ctx I::T>: DynBind<E>,
+ Dynamic<BorrowedStatic<'ctx, I::T>>: DynBind<E>,
+ for<'a, 'b> Dynamic<&'a BorrowedStatic<'b, I::T>>: DynBind<E>,
+ Dynamic<TypeId>: DynBind<E>,
+ Dynamic<OwnedStatic<TypeId>>: DynBind<E>,
}
impl<'ctx, I, S, M, E> Hint<'ctx, RecoverableProto<E>> for StructWalker<'ctx, I, S, M, E>
@@ -538,7 +543,9 @@ impl<'ctx, I, M, E> Hint<'ctx, ValueProto<BorrowedStaticHrt<I::T>, E>>
where
E: Environment,
I: StructTypeInfo<'ctx, M, E, S = StaticType>,
- I::T: IsSync<E::NeedSend> + 'static,
+ I::T: 'static,
+ for<'a, 'b> Dynamic<&'a BorrowedStatic<'b, I::T>>: DynBind<E>,
+ Dynamic<&'ctx I::T>: DynBind<E>,
{
#[inline(always)]
fn hint<'this, 'visitor, 'hint, 'e>(
@@ -640,7 +647,7 @@ where
let index = self.index;
self.index += 1;
- I::walk_field(index, self.value, visitor)
+ I::walk_field(index, self.value.0, visitor)
.map(self, |this, result| match result {
Ok(flow) => flow,
Err(err) => {
@@ -669,7 +676,12 @@ impl<'ctx, I, M: 'ctx, E> RecoverableScope<'ctx, E> for StructWalker<'ctx, I, St
where
E: Environment,
I: StructTypeInfo<'ctx, M, E, S = StaticType>,
- I::T: IsSync<E::NeedSend> + 'static,
+ I::T: 'static,
+ Dynamic<BorrowedStatic<'ctx, I::T>>: DynBind<E>,
+ for<'a, 'b> Dynamic<&'a BorrowedStatic<'b, I::T>>: DynBind<E>,
+ Dynamic<&'ctx I::T>: DynBind<E>,
+ Dynamic<TypeId>: DynBind<E>,
+ Dynamic<OwnedStatic<TypeId>>: DynBind<E>,
{
#[inline(always)]
fn new_walk<'a: 'c, 'b: 'c, 'c>(
@@ -690,7 +702,7 @@ where
})
.cast::<()>()
.if_not_finished((), |_, (this, visitor)| {
- visit_value::<_, E>(visitor.cast(), BorrowedStatic(this.value))
+ visit_value::<_, E>(visitor.cast(), BorrowedStatic(this.value.0))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
})
diff --git a/src/walk/walkers/core/value.rs b/src/walk/walkers/core/value.rs
index 9baea0e..3067a3d 100644
--- a/src/walk/walkers/core/value.rs
+++ b/src/walk/walkers/core/value.rs
@@ -2,10 +2,11 @@ use effectful::{
bound::IsSync,
effective::Effective,
environment::{DynBind, Environment, NativeForm}, SendSync,
+ bound::Dynamic
};
use crate::{
- any::{BorrowedStatic, OwnedStatic, TempBorrowedStatic},
+ any::{BorrowedStatic, OwnedStatic, TempBorrowedStatic, BorrowedStaticHrt, TempBorrowedStaticHrt},
never::Never,
protocol::{
visitor::{visit_value, EffectiveVisitExt as _, VisitResult},
@@ -18,13 +19,13 @@ use crate::{
/// Primitive types use this walker as their main walker.
/// This walker doesn't consider it an error if the visitor doesn't have the protocol.
#[derive(Debug, SendSync)]
-pub struct ValueWalker<T>(T);
+pub struct ValueWalker<T>(Dynamic<T>);
impl<T> ValueWalker<T> {
/// Create walker from a value.
#[inline(always)]
pub fn new(value: T) -> Self {
- Self(value)
+ Self(Dynamic(value))
}
}
@@ -44,7 +45,8 @@ impl<T: Copy> From<&T> for ValueWalker<T> {
impl<'ctx, T: 'static, E: Environment> crate::Walker<'ctx, E> for ValueWalker<T>
where
- T: DynBind<E>,
+ Dynamic<T>: DynBind<E>,
+ Dynamic<OwnedStatic<T>>: DynBind<E>,
{
type Error = Never;
@@ -56,7 +58,7 @@ where
visitor: DynVisitor<'b, 'ctx, E>,
) -> NativeForm<'c, Result<Self::Output, Self::Error>, E> {
// Attempt to visit using the value protocol.
- visit_value::<_, E>(visitor, OwnedStatic(self.0))
+ visit_value::<OwnedStatic<T>, E>(visitor, OwnedStatic(self.0.0))
.map((), |_, _| Ok(()))
.cast()
}
@@ -66,24 +68,26 @@ where
///
/// This walker supports values borrowed for `'ctx` or longer.
#[derive(SendSync)]
-pub struct BorrowWalker<'ctx, T: ?Sized>(&'ctx T);
+pub struct BorrowWalker<'ctx, T: ?Sized>(Dynamic<&'ctx T>);
impl<'ctx, T: ?Sized> BorrowWalker<'ctx, T> {
/// Create walker from a value.
#[inline(always)]
pub fn new(value: &'ctx T) -> Self {
- Self(value)
+ Self(Dynamic(value))
}
}
-impl<'ctx, T: ?Sized + DynBind<E> + 'static, E: Environment> crate::Walker<'ctx, E>
+impl<'ctx, T: ?Sized + 'static, E: Environment> crate::Walker<'ctx, E>
for BorrowWalker<'ctx, T>
where
- T: IsSync<E::NeedSend>,
+ Dynamic<&'ctx T>: DynBind<E>,
+ Dynamic<BorrowedStatic<'ctx, T>>: DynBind<E>,
+ for<'a> Dynamic<TempBorrowedStatic<'a, T>>: DynBind<E>
{
type Error = Never;
- type Output = &'ctx T;
+ type Output = Dynamic<&'ctx T>;
#[inline(always)]
fn walk<'b: 'c, 'c>(
@@ -93,12 +97,12 @@ where
// Attempt to visit using the value protocol.
E::value((self, visitor))
.update((), |_, (this, visitor)| {
- visit_value::<_, E>(visitor.cast(), BorrowedStatic(this.0))
+ visit_value::<_, E>(visitor.cast(), BorrowedStatic(this.0.0))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
})
.if_skipped((), |_, (this, visitor)| {
- visit_value::<_, E>(visitor.cast(), TempBorrowedStatic(this.0))
+ visit_value::<_, E>(visitor.cast(), TempBorrowedStatic(this.0.0))
.map((), |_, x| VisitResult::unit_skipped(x))
.cast()
})
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!()
diff --git a/tests/builder_enum.rs b/tests/builder_enum.rs
index 91ab6ac..fed91e0 100644
--- a/tests/builder_enum.rs
+++ b/tests/builder_enum.rs
@@ -18,7 +18,7 @@ use crate::common::{
};
use effectful::{
- effective::Effective, environment::{Environment, NativeForm}, SendSync
+ effective::Effective, environment::{Environment, NativeForm}, SendSync, bound::Dynamic
};
use macro_rules_attribute::derive;
@@ -44,7 +44,7 @@ fn enum_builder_takes_unsigned_integer_variant_tag() {
builder.visit_value_and_done(OwnedStatic(1.23f32));
}
- assert_eq!(builder.build().into_value().unwrap(), X::A(1.23));
+ assert_eq!(builder.build().into_value().unwrap().0, X::A(1.23));
}
#[test]
@@ -60,7 +60,7 @@ fn enum_builder_takes_string_variant_tag() {
builder.visit_value_and_done(OwnedStatic(1.23f32));
}
- assert_eq!(builder.build().into_value().unwrap(), X::A(1.23));
+ assert_eq!(builder.build().into_value().unwrap().0, X::A(1.23));
}
#[test]
@@ -93,5 +93,5 @@ fn enum_builder_can_guess_the_variant() {
}
// The enum should have a value now.
- assert_eq!(builder.build().into_value().unwrap(), X::B(true));
+ assert_eq!(builder.build().into_value().unwrap().0, X::B(true));
}
diff --git a/tests/builder_struct.rs b/tests/builder_struct.rs
index d63e572..1a8ec6f 100644
--- a/tests/builder_struct.rs
+++ b/tests/builder_struct.rs
@@ -1,3 +1,4 @@
+/*
use effectful::SendSync;
use macro_rules_attribute::derive;
use treaty::{
@@ -61,7 +62,7 @@ fn a_struct_builder_can_build_from_a_sequence_of_field_values() {
));
// The builder should be able to build a instance of the struct.
- assert_eq!(builder.build().into_value().unwrap(), X { a: true, b: false });
+ assert_eq!(builder.build().into_value().unwrap().0, X { a: true, b: false });
}
#[test]
@@ -146,5 +147,6 @@ fn a_struct_builder_can_build_from_a_sequence_of_keyed_values() {
);
// The struct is built as the mock walker above makes it.
- assert_eq!(builder.build().into_value().unwrap(), X { a: false, b: true });
+ assert_eq!(builder.build().into_value().unwrap().0, X { a: false, b: true });
}
+*/
diff --git a/tests/builder_value.rs b/tests/builder_value.rs
index 3adabf4..fa4e1ab 100644
--- a/tests/builder_value.rs
+++ b/tests/builder_value.rs
@@ -40,7 +40,7 @@ fn value_builder_gives_value_protocol_as_hint() {
);
// The builder should have the value.
- assert_eq!(builder.build().into_value().unwrap(), 42);
+ assert_eq!(builder.build().into_value().unwrap().0, 42);
}
#[test]
diff --git a/tests/common/builder.rs b/tests/common/builder.rs
index b2bb1ff..d4fc3c7 100644
--- a/tests/common/builder.rs
+++ b/tests/common/builder.rs
@@ -1,6 +1,6 @@
use core::fmt::{Debug, Display};
use effectful::{
- bound::{Bool, DynamicShim, IsSend, IsSync}, effective::Effective, environment::{DynBind, Environment, NativeForm}, forward_send_sync, SendSync
+ bound::{Bool, Dynamic, DynamicShim, IsSend, IsSync}, effective::Effective, environment::{DynBind, Environment, NativeForm}, forward_send_sync, SendSync
};
use mockall::mock;
use treaty::{
@@ -34,20 +34,26 @@ mock! {
}
}
-forward_send_sync!({Seed: ('static), Value: ('static), Error: ('static)} {} {E: (Environment)} MockBuilder<Seed, Value, Error, E>);
+forward_send_sync!({Seed: ('static), Error: ('static)} {} {Value: ('static), E: (Environment)} MockBuilder<Seed, Value, Error, E>);
impl<Seed, Value, Error: Display + Debug, E: Environment> BuilderTypes<E>
for MockBuilder<Seed, Value, Error, E>
where
Seed: DynBind<E>,
- Value: DynBind<E>,
+ Dynamic<Value>: DynBind<E>,
Error: DynBind<E>,
{
type Seed = Seed;
type Error = Error;
+ type Output = Dynamic<Value>;
+
type Value = Value;
+
+ fn unwrap_output(output: Self::Output) -> Self::Value {
+ output.0
+ }
}
impl<Seed: 'static, Value: 'static, Error: 'static, E: Environment>
@@ -69,10 +75,12 @@ impl<Seed: 'static, Value: 'static, Error: 'static, E: Environment>
impl<
'ctx,
Seed: DynBind<E>,
- Value: DynBind<E>,
+ Value,
Error: DynBind<E> + Display + Debug,
E: Environment,
> Builder<'ctx, E> for MockBuilder<Seed, Value, Error, E>
+where
+ Dynamic<Value>: DynBind<E>
{
fn from_seed<'a>(seed: Self::Seed) -> NativeForm<'a, Self, E>
where
@@ -81,11 +89,11 @@ impl<
E::value(Self::from_seed(seed)).cast()
}
- fn build<'a>(self) -> NativeForm<'a, Result<Self::Value, Self::Error>, E>
+ fn build<'a>(self) -> NativeForm<'a, Result<Self::Output, Self::Error>, E>
where
Self: 'a,
{
- E::value(self.build()).cast()
+ E::value(self.build().map(Dynamic)).cast()
}
}
@@ -93,8 +101,8 @@ impl<'ctx, Seed, Value, Error: Display + Debug, E: Environment> AsVisitor<'ctx,
for MockBuilder<Seed, Value, Error, E>
where
Seed: DynBind<E>,
- Value: DynBind<E>,
Error: DynBind<E>,
+ Dynamic<Value>: DynBind<E>
{
fn as_visitor<'a>(&'a mut self) -> DynVisitor<'a, 'ctx, E>
where
@@ -108,8 +116,8 @@ impl<'ctx, Seed, Value, Error, E: Environment> AnyTrait<'ctx, E>
for MockBuilder<Seed, Value, Error, E>
where
Seed: DynBind<E>,
- Value: DynBind<E>,
Error: DynBind<E>,
+ Dynamic<Value>: DynBind<E>,
{
fn upcast_to_id<'a>(
&'a self,
diff --git a/tests/common/protocol/value.rs b/tests/common/protocol/value.rs
index 038853a..4f1e5c9 100644
--- a/tests/common/protocol/value.rs
+++ b/tests/common/protocol/value.rs
@@ -1,6 +1,6 @@
use effectful::{
- environment::{Environment, NativeForm},
- bound::{Bool, IsSend, IsSync},
+ environment::{Environment, NativeForm, DynBind},
+ bound::{Bool, IsSend, IsSync, Dynamic},
effective::Effective,
forward_send_sync,
};
@@ -25,7 +25,7 @@ mock! {
}
}
-forward_send_sync!({T: (TypeName::MemberType<E>)} {} {E: (Environment)} MockValueVisitor<T, E> where {
+forward_send_sync!({} {} {T: (TypeName::MemberType<E>), E: (Environment)} MockValueVisitor<T, E> where {
for<'a, 'ctx> TypeName::T<'a, 'ctx, T, E>: Sized
});
@@ -35,22 +35,24 @@ any_trait! {
] where
T: TypeName::MemberType<E>,
for<'a, 'b> TypeName::T<'a, 'b, T, E>: Sized,
+ for<'a> Dynamic<TypeName::T<'a, 'ctx, T, E>>: DynBind<E>,
E: Environment,
}
impl<'ctx, T: TypeName::MemberType<E>, E: Environment> Value<'ctx, T, E> for MockValueVisitor<T, E>
where
for<'a, 'lt> TypeName::T<'a, 'lt, T, E>: Sized,
+ for<'a> Dynamic<TypeName::T<'a, 'ctx, T, E>>: DynBind<E>,
{
fn visit<'a>(
&'a mut self,
value: TypeName::T<'a, 'ctx, T, E>,
- ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, T, E>>, E>
+ ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, T, E>>>, E>
where
'ctx: 'a,
{
E::value(match self.visit(&value) {
- VisitResult::Skipped(_) => VisitResult::Skipped(value),
+ VisitResult::Skipped(_) => VisitResult::Skipped(Dynamic(value)),
VisitResult::Control(flow) => VisitResult::Control(flow),
}).cast()
}
@@ -74,6 +76,7 @@ impl<'ctx, U> ValueVisitorExt<'ctx> for U
where
U: AsVisitor<'ctx, Blocking>,
{
+ #[track_caller]
fn visit_value_and_done<'a, T>(&'a mut self, value: T)
where
T: TypeName::LowerType<'a, 'ctx, Blocking>,
@@ -85,6 +88,7 @@ where
assert_eq!(result, VisitResult::Control(Flow::Done));
}
+ #[track_caller]
fn visit_value_and_skipped<'a, T>(&'a mut self, value: T)
where
T: TypeName::LowerType<'a, 'ctx, Blocking>,
diff --git a/tests/protocol_visitor_request_hint.rs b/tests/protocol_visitor_request_hint.rs
index 40634ac..783c37e 100644
--- a/tests/protocol_visitor_request_hint.rs
+++ b/tests/protocol_visitor_request_hint.rs
@@ -15,6 +15,7 @@ use treaty::{
Flow,
};
+use effectful::bound::Dynamic;
use crate::common::{protocol::hint::KnownFactory, Blocking};
mod common;
@@ -34,7 +35,7 @@ fn hints_can_be_requested() {
assert_eq!(
obj.known(&()).into_value(),
Ok(ValueKnown {
- preview: Some(&OwnedStatic(42))
+ preview: Some(Dynamic(&OwnedStatic(42)))
})
);
@@ -60,7 +61,7 @@ fn hints_can_be_requested() {
mock.expect_known().once().return_const(
(|_, ()| {
Ok(ValueKnown {
- preview: Some(&OwnedStatic(42)),
+ preview: Some(Dynamic(&OwnedStatic(42))),
})
}) as KnownFactory<ValueProto<OwnedStatic<i32>, Blocking>>,
);
diff --git a/tests/protocol_visitor_value.rs b/tests/protocol_visitor_value.rs
index a566670..13e6367 100644
--- a/tests/protocol_visitor_value.rs
+++ b/tests/protocol_visitor_value.rs
@@ -5,6 +5,7 @@ use common::protocol::{
value::MockValueVisitor,
};
use effectful::SendSync;
+use effectful::bound::Dynamic;
use mockall::predicate::eq;
use treaty::{
any::{
@@ -206,7 +207,7 @@ fn all_visit_results() {
// The value should be given back, but that's not forced.
assert_eq!(
visitor.visit(OwnedStatic(3)).into_value(),
- VisitResult::Skipped(OwnedStatic(3))
+ VisitResult::Skipped(Dynamic(OwnedStatic(3)))
);
}
@@ -234,7 +235,7 @@ fn as_hint() {
mock.expect_known().once().return_const(
(|_, _hint| {
Ok(ValueKnown {
- preview: Some(&OwnedStatic(42)),
+ preview: Some(Dynamic(&OwnedStatic(42))),
})
}) as KnownFactory<ValueProto<OwnedStatic<i32>, Blocking>>,
);
@@ -245,7 +246,7 @@ fn as_hint() {
assert_eq!(
walker.known(&()).into_value(),
Ok(ValueKnown {
- preview: Some(&OwnedStatic(42))
+ preview: Some(Dynamic(&OwnedStatic(42)))
})
);
}
@@ -256,7 +257,7 @@ fn as_hint() {
mock.expect_known().once().return_const(
(|_, _hint| {
Ok(ValueKnown {
- preview: Some(&BorrowedStatic(&42)),
+ preview: Some(Dynamic(&BorrowedStatic(&42))),
})
}) as KnownFactory<ValueProto<BorrowedStaticHrt<i32>, Blocking>>,
);
@@ -267,7 +268,7 @@ fn as_hint() {
assert_eq!(
walker.known(&()).into_value(),
Ok(ValueKnown {
- preview: Some(&BorrowedStatic(&42))
+ preview: Some(Dynamic(&BorrowedStatic(&42)))
})
);
}
diff --git a/tests/serde_deserializer.rs b/tests/serde_deserializer.rs
index a0e8792..ee9d7ae 100644
--- a/tests/serde_deserializer.rs
+++ b/tests/serde_deserializer.rs
@@ -1,41 +1,42 @@
-// use serde_json::json;
-// use treaty::walkers::serde::deserializer::DeserializerWalker;
-// use treaty::{Build, BuildExt as _};
-//
-// use macro_rules_attribute::derive;
-//
-// mod common;
-//
-// #[test]
-// fn demo() {
-// let x = json!(true);
-//
-// let y = bool::build(DeserializerWalker::new(x));
-//
-// assert!(y.unwrap());
-// }
-//
-// #[test]
-// fn demo2() {
-// let x = json!(42);
-//
-// let mut de = serde_json::Deserializer::from_str("42");
-// let y = u8::build(DeserializerWalker::new(&mut de));
-//
-// assert_eq!(y.unwrap(), 42);
-// }
-//
-// #[derive(Build!, Debug, PartialEq)]
-// struct X {
-// a: bool,
-// b: i64,
-// }
-//
-// #[test]
-// fn demo3() {
-// let x = json!({ "a": true, "b": 42 });
-//
-// let y = X::build(DeserializerWalker::new(x));
-//
-// assert_eq!(y.unwrap(), X { a: true, b: 101 });
-// }
+use serde_json::json;
+use treaty::walkers::serde::deserializer::DeserializerWalker;
+use treaty::{Build, BuildExt as _, transform};
+
+use macro_rules_attribute::derive;
+use effectful::SendSync;
+
+mod common;
+
+#[test]
+fn demo() {
+ let x = json!(true);
+
+ let y = bool::build(DeserializerWalker::new(x));
+
+ assert!(y.unwrap());
+}
+
+#[test]
+fn demo2() {
+ let x = json!(42);
+
+ let mut de = serde_json::Deserializer::from_str("42");
+ let y = u8::build(DeserializerWalker::new(&mut de));
+
+ assert_eq!(y.unwrap(), 42);
+}
+
+#[derive(Build!, Debug, PartialEq)]
+struct X {
+ a: bool,
+ b: i64,
+}
+
+#[test]
+fn demo3() {
+ let x = json!({ "a": true, "b": 42 });
+
+ let y = X::build(DeserializerWalker::new(x));
+
+ assert_eq!(y.unwrap(), X { a: true, b: 42 });
+}
diff --git a/tests/walker_struct.rs b/tests/walker_struct.rs
index f4cc910..01ae867 100644
--- a/tests/walker_struct.rs
+++ b/tests/walker_struct.rs
@@ -1,5 +1,5 @@
use effectful::{
- bound::{DynamicShim, ForceDynamic}, effective::Effective, environment::{Environment, NativeForm}, SendSync
+ bound::{DynamicShim, ForceDynamic, Dynamic}, effective::Effective, environment::{Environment, NativeForm, DynBind}, SendSync
};
use mockall::predicate::eq;
use treaty::{
@@ -29,7 +29,11 @@ struct X {
struct Info;
// This gives the struct walker enough information to walk the X struct.
-impl<'ctx, M, E: Environment> StructTypeInfo<'ctx, M, E> for Info {
+impl<'ctx, M, E: Environment> StructTypeInfo<'ctx, M, E> for Info
+where
+ Dynamic<OwnedStatic<bool>>: DynBind<E>,
+ Dynamic<OwnedStatic<i32>>: DynBind<E>,
+{
const NAME: &'static str = "X";
const FIELDS: &'static [&'static str] = &["a", "b"];