| -rw-r--r-- | Cargo.toml | 7 | ||||
| -rw-r--r-- | src/lib.rs | 28 | ||||
| -rw-r--r-- | src/protocol/visitor/tag.rs | 6 | ||||
| -rw-r--r-- | src/transform.rs | 22 | ||||
| -rw-r--r-- | src/walk.rs | 34 | ||||
| -rw-r--r-- | src/walk/walkers.rs | 3 | ||||
| -rw-r--r-- | src/walk/walkers/core/bool.rs | 12 | ||||
| -rw-r--r-- | src/walk/walkers/core/key_value.rs | 16 | ||||
| -rw-r--r-- | src/walk/walkers/core/noop.rs | 5 | ||||
| -rw-r--r-- | src/walk/walkers/core/struct.rs | 51 | ||||
| -rw-r--r-- | src/walk/walkers/core/tag.rs | 16 | ||||
| -rw-r--r-- | src/walk/walkers/core/value.rs | 13 | ||||
| -rw-r--r-- | src/walk/walkers/serde.rs | 1 | ||||
| -rw-r--r-- | src/walk/walkers/serde/deserializer.rs | 15 | ||||
| -rw-r--r-- | tests/common/walker.rs | 8 | ||||
| -rw-r--r-- | tests/walker_struct.rs | 4 |
16 files changed, 111 insertions, 130 deletions
@@ -13,14 +13,13 @@ readme = "README.md" macro_rules_attribute = "0.2.0" futures = "0.3.30" pin-project = "1.1.5" -# serde = { version = "1.0", default-features = false, optional = true } -serde = { version = "1.0", features = ["serde_derive"] } +serde = { version = "1.0", default-features = false, optional = true } [features] -default = ["std", "better_errors"] +default = ["std", "serde"] std = ["alloc"] alloc = [] -# serde = ["dep:serde"] +serde = ["dep:serde"] better_errors = [] [dev-dependencies] @@ -132,33 +132,37 @@ macro_rules! Walk { } } - impl<'ctx> $crate::WalkerTypes for &'ctx $name { - type Error = $crate::walkers::core::r#struct::StructWalkError<FieldError<'ctx>>; - type Output = (); - } + // impl<'ctx> $crate::WalkerTypes for &'ctx $name { + // type Error = $crate::walkers::core::r#struct::StructWalkError<FieldError<'ctx>>; + // type Output = (); + // } $vis enum Info {} - #[derive(Debug)] #[allow(non_camel_case_types, unused)] - enum FieldErrorKind<'ctx> {$( - $field($crate::walkers::core::key_value::KeyValueError<$crate::never::Never, <&'ctx $type as $crate::WalkerTypes>::Error>) + enum FieldErrorKind<'ctx, M, E: $crate::effect::Effect> {$( + $field($crate::walkers::core::key_value::KeyValueError<$crate::never::Never, <<&'ctx $type as $crate::Walk<'ctx, M, E>>::Walker as $crate::Walker<'ctx, E>>::Error>) ),*} - #[derive(Debug)] #[allow(unused)] - $vis struct FieldError<'ctx>(FieldErrorKind<'ctx>); + $vis struct FieldError<'ctx, M, E: $crate::effect::Effect>(FieldErrorKind<'ctx, M, E>); + + impl<'ctx, M, E: $crate::effect::Effect> ::core::fmt::Debug for FieldError<'ctx, M, E> { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + todo!() + } + } - impl<'ctx, M: 'ctx> $crate::walkers::core::r#struct::StructTypeInfo<'ctx, M> for Info { + impl<'ctx, M: 'ctx, E: $crate::effect::Effect> $crate::walkers::core::r#struct::StructTypeInfo<'ctx, M, E> for Info { const NAME: &'static str = stringify!($name); const FIELDS: &'static [&'static str] = &[$(stringify!($field)),*]; - type FieldError = FieldError<'ctx>; + type FieldError = FieldError<'ctx, M, E>; type T = $name; type S = $crate::any::StaticType; #[allow(unreachable_code, non_snake_case, non_upper_case_globals, non_camel_case_types)] - fn walk_field<'a, E: $crate::effect::Effect>( + fn walk_field<'a>( index: usize, value: &'ctx Self::T, visitor: $crate::protocol::DynVisitor<'a, 'ctx>, diff --git a/src/protocol/visitor/tag.rs b/src/protocol/visitor/tag.rs index ca32016..a1f189b 100644 --- a/src/protocol/visitor/tag.rs +++ b/src/protocol/visitor/tag.rs @@ -9,7 +9,7 @@ use crate::{ DynVisitor, }, symbol::Symbol, - tri, DynWalkerAdapter, DynWalkerError, DynWalkerObjSafe, WalkerTypes, + tri, DynWalkerAdapter, DynWalkerError, DynWalkerObjSafe, Walker, }; use super::VisitResult; @@ -210,9 +210,9 @@ pub fn visit_tag< }) } -fn map_walker_err<K: TagKind, W: WalkerTypes>( +fn map_walker_err<'ctx, K: TagKind, W: Walker<'ctx, E>, E: Effect>( kind: K, - err: DynWalkerError<W>, + err: DynWalkerError<'ctx, W, E>, ) -> TagError<W::Error> { match err { DynWalkerError::Walker(err) => TagError::new(kind, err), diff --git a/src/transform.rs b/src/transform.rs index 4d9e99d..b9cc346 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -5,7 +5,7 @@ use crate::{ effect::{ blocking::Blocking, r#async::Async, Effect, Effective, EffectiveExt, ErasedEffective, }, - Build, BuilderTypes, DefaultMode, Walk, Walker, WalkerTypes, + Build, BuilderTypes, DefaultMode, Walk, Walker, }; #[inline(always)] @@ -37,19 +37,15 @@ pub fn transform<'a, 'ctx: 'a, B: Builder<'ctx, E> + 'a, W: Walker<'ctx, E> + 'a // }) } -pub enum BuildError<B, W> -where - B: BuilderTypes, - W: WalkerTypes, -{ - Builder(B::Error), - Both(B::Error, W::Error), +pub enum BuildError<B, W> { + Builder(B), + Both(B, W), } -impl<B, W> core::fmt::Debug for BuildError<B, W> +impl<B, W> core::fmt::Debug for BuildError<B, W> where - B: BuilderTypes, - W: WalkerTypes, + B: core::fmt::Debug, + W: core::fmt::Debug, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { @@ -61,7 +57,7 @@ where pub trait BuildExt { /// Build a value of this type using the default builder. - fn build<'ctx, W>(walker: W) -> Result<Self, BuildError<Self::Builder, W>> + fn build<'ctx, W>(walker: W) -> Result<Self, BuildError<<Self::Builder as BuilderTypes>::Error, <W as Walker<'ctx, Blocking>>::Error>> where Self: Build<'ctx, DefaultMode, Blocking>, <Self::Builder as BuilderTypes>::Seed: Default, @@ -76,7 +72,7 @@ pub trait BuildExt { fn build_async<'ctx, W>( walker: W, - ) -> impl Future<Output = Result<Self, BuildError<Self::Builder, W>>> + Send + Sync + ) -> impl Future<Output = Result<Self, BuildError<<Self::Builder as BuilderTypes>::Error, <W as Walker<'ctx, Async>>::Error>>> + Send + Sync where Self: Build<'ctx, DefaultMode, Async>, <Self::Builder as BuilderTypes>::Seed: Default, diff --git a/src/walk.rs b/src/walk.rs index 0e02306..692c963 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -19,15 +19,6 @@ pub trait Walk<'ctx, M, E: Effect>: Sized { Self: 'e; } -pub trait WalkerTypes { - type Error: Send + Sync + Debug; - - /// An arbitrary type the walker is left with after walking. - /// - /// Its recommended that this is `Self` if the walker is repeatable. - type Output: Send + Sync; -} - /// Walker for a type. /// /// The `'ctx` lifetime is some lifetime that is longer than `Self`. @@ -37,7 +28,14 @@ pub trait WalkerTypes { /// - Call [From::from()] with a value to be walked to make a walker. /// - Call [Self::walk()] to walk the value. Data will be sent to the provided /// visitor. -pub trait Walker<'ctx, E: Effect>: WalkerTypes + Send + Sync { +pub trait Walker<'ctx, E: Effect>: Send + Sync { + type Error: Send + Sync + Debug; + + /// An arbitrary type the walker is left with after walking. + /// + /// Its recommended that this is `Self` if the walker is repeatable. + type Output: Send + Sync; + /// Walk the value. /// /// The walker should send data to the `visitor` as it walks the value. @@ -60,14 +58,14 @@ pub trait WalkerObjSafe<'ctx, E: Effect>: Send { pub type DynWalkerObjSafe<'a, 'ctx, E> = &'a mut (dyn WalkerObjSafe<'ctx, E> + Send + Sync + 'a); -enum DynWalkerState<W: WalkerTypes> { +enum DynWalkerState<'ctx, W: Walker<'ctx, E>, E: Effect> { Walking, Pending(W), Done(W::Output), Err(W::Error), } -pub enum DynWalkerError<W: WalkerTypes> { +pub enum DynWalkerError<'ctx, W: Walker<'ctx, E>, E: Effect> { NeverWalked(W), /// This can only happen if a panic happens furing the walk and is then caught before calling @@ -79,11 +77,11 @@ pub enum DynWalkerError<W: WalkerTypes> { WasWalked(W::Output), } -pub struct DynWalkerAdapter<W: WalkerTypes> { - state: DynWalkerState<W>, +pub struct DynWalkerAdapter<'ctx, W: Walker<'ctx, E>, E: Effect> { + state: DynWalkerState<'ctx, W, E>, } -impl<W: WalkerTypes> DynWalkerAdapter<W> { +impl<'ctx, W: Walker<'ctx, E>, E: Effect> DynWalkerAdapter<'ctx, W, E> { #[inline(always)] pub fn new(walker: W) -> Self { Self { @@ -92,7 +90,7 @@ impl<W: WalkerTypes> DynWalkerAdapter<W> { } #[inline(always)] - pub fn finish(self) -> Result<W::Output, DynWalkerError<W>> { + pub fn finish(self) -> Result<W::Output, DynWalkerError<'ctx, W, E>> { match self.state { DynWalkerState::Walking => Err(DynWalkerError::WalkNeverFinished), DynWalkerState::Pending(walker) => Err(DynWalkerError::NeverWalked(walker)), @@ -102,7 +100,7 @@ impl<W: WalkerTypes> DynWalkerAdapter<W> { } #[inline(always)] - pub fn into_inner(self) -> Result<W, DynWalkerError<W>> { + pub fn into_inner(self) -> Result<W, DynWalkerError<'ctx, W, E>> { match self.state { DynWalkerState::Walking => Err(DynWalkerError::WalkNeverFinished), DynWalkerState::Pending(walker) => Ok(walker), @@ -112,7 +110,7 @@ impl<W: WalkerTypes> DynWalkerAdapter<W> { } } -impl<'ctx, W: Walker<'ctx, E>, E: Effect> WalkerObjSafe<'ctx, E> for DynWalkerAdapter<W> { +impl<'ctx, W: Walker<'ctx, E>, E: Effect> WalkerObjSafe<'ctx, E> for DynWalkerAdapter<'ctx, W, E> { #[inline(always)] fn walk<'a: 'c, 'b: 'c, 'c>( &'a mut self, diff --git a/src/walk/walkers.rs b/src/walk/walkers.rs index 5a7ca06..f5eac87 100644 --- a/src/walk/walkers.rs +++ b/src/walk/walkers.rs @@ -1 +1,4 @@ pub mod core; + +#[cfg(feature = "serde")] +pub mod serde; diff --git a/src/walk/walkers/core/bool.rs b/src/walk/walkers/core/bool.rs index 890db00..13ae546 100644 --- a/src/walk/walkers/core/bool.rs +++ b/src/walk/walkers/core/bool.rs @@ -1,6 +1,6 @@ use crate::{ effect::{Effect, ErasedEffective}, - Walk, WalkerTypes, + Walk, }; use super::value::ValueWalker; @@ -13,11 +13,6 @@ impl<'ctx, M, E: Effect> Walk<'ctx, M, E> for bool { } } -impl WalkerTypes for bool { - type Error = <ValueWalker<bool> as WalkerTypes>::Error; - type Output = <ValueWalker<bool> as WalkerTypes>::Output; -} - impl<'ctx, M, E: Effect> Walk<'ctx, M, E> for &'ctx bool { type Walker = ValueWalker<bool>; @@ -25,8 +20,3 @@ impl<'ctx, M, E: Effect> Walk<'ctx, M, E> for &'ctx bool { E::ready(ValueWalker::new(*self)) } } - -impl<'ctx> WalkerTypes for &'ctx bool { - type Error = <ValueWalker<bool> as WalkerTypes>::Error; - type Output = <ValueWalker<bool> as WalkerTypes>::Output; -} diff --git a/src/walk/walkers/core/key_value.rs b/src/walk/walkers/core/key_value.rs index 1229375..71af08f 100644 --- a/src/walk/walkers/core/key_value.rs +++ b/src/walk/walkers/core/key_value.rs @@ -5,7 +5,7 @@ use crate::{ visitor::{tags, visit_tag, EffectiveVisitExt as _, TagConst, TagError, TagKind}, DynVisitor, }, - Flow, WalkerTypes, + Flow, }; pub struct KeyValueWalker<T, K, V> { @@ -36,16 +36,6 @@ enum KeyValueErrorKind<K, V> { #[derive(Debug)] pub struct KeyValueError<K, V>(KeyValueErrorKind<K, V>); -impl<T, K, V> WalkerTypes for KeyValueWalker<T, K, V> -where - K: WalkerTypes, - V: WalkerTypes, -{ - type Error = KeyValueError<K::Error, V::Error>; - - type Output = (); -} - impl<'ctx, T, K, V, E> crate::Walker<'ctx, E> for KeyValueWalker<T, K, V> where E: Effect, @@ -53,6 +43,10 @@ where K: crate::Walker<'ctx, E> + 'ctx, V: crate::Walker<'ctx, E> + 'ctx, { + type Error = KeyValueError<K::Error, V::Error>; + + type Output = (); + #[inline(always)] fn walk<'b: 'c, 'c>( self, diff --git a/src/walk/walkers/core/noop.rs b/src/walk/walkers/core/noop.rs index e26eba4..ec8e5b8 100644 --- a/src/walk/walkers/core/noop.rs +++ b/src/walk/walkers/core/noop.rs @@ -2,7 +2,6 @@ use crate::{ effect::{Effect, ErasedEffective}, never::Never, protocol::DynVisitor, - WalkerTypes, }; /// A walker that does nothing. @@ -18,13 +17,11 @@ impl NoopWalker { } } -impl WalkerTypes for NoopWalker { +impl<'ctx, E: Effect> crate::Walker<'ctx, E> for NoopWalker { type Error = Never; type Output = (); -} -impl<'ctx, E: Effect> crate::Walker<'ctx, E> for NoopWalker { fn walk<'b: 'c, 'c>( self, _visitor: DynVisitor<'b, 'ctx>, diff --git a/src/walk/walkers/core/struct.rs b/src/walk/walkers/core/struct.rs index d98043d..e6138fb 100644 --- a/src/walk/walkers/core/struct.rs +++ b/src/walk/walkers/core/struct.rs @@ -16,7 +16,7 @@ use crate::{ walker::hint::{Hint, HintMeta, HintProto, MetaHint, MetaKnown}, DynVisitor, DynWalker, }, - DynWalkerAdapter, Flow, Status, WalkerTypes, TAG_FIELD_NAMES, TAG_MAP, TAG_STRUCT, TAG_TYPE_ID, + DynWalkerAdapter, Flow, Status, TAG_FIELD_NAMES, TAG_MAP, TAG_STRUCT, TAG_TYPE_ID, TAG_TYPE_NAME, }; @@ -25,7 +25,7 @@ use super::{noop::NoopWalker, value::ValueWalker}; /// Walker for a borrow of a struct. /// /// This walker implements the struct flow. The struct cannot contain lifetimes. -pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, S = S>, S, M, E> { +pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Effect> { /// Struct value to walk. value: &'ctx I::T, @@ -41,7 +41,7 @@ pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, S = S>, S, M, E> { } /// Type info about a struct needed by [`StructWalker`]. -pub trait StructTypeInfo<'ctx, M>: 'static { +pub trait StructTypeInfo<'ctx, M, E: Effect>: 'static { /// Name of the struct. const NAME: &'static str; @@ -57,7 +57,7 @@ pub trait StructTypeInfo<'ctx, M>: 'static { type T: Send + Sync; /// Walk the given field. - fn walk_field<'a, E: Effect>( + fn walk_field<'a>( index: usize, value: &'ctx Self::T, visitor: DynVisitor<'a, 'ctx>, @@ -88,9 +88,9 @@ pub struct StructWalkError<T> { kind: StructWalkErrorKind<T>, } -impl<'ctx, I, S, M, E> StructWalker<'ctx, I, S, M, E> +impl<'ctx, I, S, M, E: Effect> StructWalker<'ctx, I, S, M, E> where - I: StructTypeInfo<'ctx, M, S = S>, + I: StructTypeInfo<'ctx, M, E, S = S>, { /// Create walker from a borrow of a struct. pub fn new(value: &'ctx I::T) -> Self { @@ -113,20 +113,15 @@ where } } -impl<'ctx, I, S, M, E> WalkerTypes for StructWalker<'ctx, I, S, M, E> -where - I: StructTypeInfo<'ctx, M, S = S>, -{ - type Error = StructWalkError<I::FieldError>; - type Output = (); -} - impl<'ctx, I, S, E, M> crate::Walker<'ctx, E> for StructWalker<'ctx, I, S, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = S>, + I: StructTypeInfo<'ctx, M, E, S = S>, Self: AnyTrait<'ctx> + RecoverableScope<'ctx, E>, { + type Error = StructWalkError<I::FieldError>; + type Output = (); + #[inline(always)] fn walk<'b: 'c, 'c>( self, @@ -177,7 +172,7 @@ any_trait! { HintProto<TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>, ] where E: Effect, - I: StructTypeInfo<'ctx, M, S = StaticType>, + I: StructTypeInfo<'ctx, M, E, S = StaticType>, M: 'ctx, I::T: 'static } @@ -185,7 +180,7 @@ any_trait! { impl<'ctx, I, S, M, E> Hint<'ctx, RecoverableProto<E>> for StructWalker<'ctx, I, S, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = S>, + I: StructTypeInfo<'ctx, M, E, S = S>, Self: AnyTrait<'ctx> + RecoverableScope<'ctx, E>, { #[inline(always)] @@ -220,7 +215,7 @@ impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() } for StructWalker<'ctx, I, S, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = S>, + I: StructTypeInfo<'ctx, M, E, S = S>, { #[inline(always)] fn hint<'this, 'visitor, 'hint, 'e>( @@ -268,7 +263,7 @@ impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, for StructWalker<'ctx, I, S, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = S>, + I: StructTypeInfo<'ctx, M, E, S = S>, { #[inline(always)] fn hint<'this, 'visitor, 'hint, 'e>( @@ -316,7 +311,7 @@ impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>> for StructWalker<'ctx, I, S, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = S>, + I: StructTypeInfo<'ctx, M, E, S = S>, { #[inline(always)] fn hint<'this, 'visitor, 'hint, 'e>( @@ -360,7 +355,7 @@ impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E> for StructWalker<'ctx, I, S, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = S>, + I: StructTypeInfo<'ctx, M, E, S = S>, { #[inline(always)] fn hint<'this: 'e, 'visitor: 'e, 'hint: 'e, 'e>( @@ -403,7 +398,7 @@ impl<'ctx, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>> for StructWalker<'ctx, I, StaticType, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = StaticType>, + I: StructTypeInfo<'ctx, M, E, S = StaticType>, I::T: 'static, { #[inline(always)] @@ -451,7 +446,7 @@ where impl<'ctx, I, M, E> Hint<'ctx, TagProto<TagDyn, E>> for StructWalker<'ctx, I, StaticType, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = StaticType>, + I: StructTypeInfo<'ctx, M, E, S = StaticType>, I::T: 'static, { #[inline(always)] @@ -519,7 +514,7 @@ impl<'ctx, I, M, E> Hint<'ctx, ValueProto<BorrowedStaticHrt<I::T>, E>> for StructWalker<'ctx, I, StaticType, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = StaticType>, + I: StructTypeInfo<'ctx, M, E, S = StaticType>, I::T: 'static, { #[inline(always)] @@ -553,7 +548,7 @@ where impl<'ctx, I, S, M: 'ctx, E> Hint<'ctx, SequenceProto<E>> for StructWalker<'ctx, I, S, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = S>, + I: StructTypeInfo<'ctx, M, E, S = S>, { #[inline(always)] @@ -592,7 +587,7 @@ where impl<'ctx, I, S, M: 'ctx, E> SequenceScope<'ctx, E> for StructWalker<'ctx, I, S, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = S>, + I: StructTypeInfo<'ctx, M, E, S = S>, { #[inline(always)] fn size_hint(&mut self) -> ErasedEffective<'_, (usize, Option<usize>), E> { @@ -613,7 +608,7 @@ where let index = self.index; self.index += 1; - I::walk_field::<E>(index, self.value, visitor).map(|result| match result { + I::walk_field(index, self.value, visitor).map(|result| match result { Ok(flow) => flow, Err(err) => { // Record the error and signal a break. @@ -639,7 +634,7 @@ where impl<'ctx, I, M: 'ctx, E> RecoverableScope<'ctx, E> for StructWalker<'ctx, I, StaticType, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M, S = StaticType>, + I: StructTypeInfo<'ctx, M, E, S = StaticType>, I::T: 'static, { #[inline(always)] diff --git a/src/walk/walkers/core/tag.rs b/src/walk/walkers/core/tag.rs index 47c8e27..7203fe8 100644 --- a/src/walk/walkers/core/tag.rs +++ b/src/walk/walkers/core/tag.rs @@ -8,7 +8,7 @@ use crate::{ visitor::{SequenceScope, TagError}, DynVisitor, }, - Flow, WalkerTypes, + Flow, }; pub struct StaticSliceWalker<T: 'static, W> { @@ -27,19 +27,17 @@ impl<T, W> StaticSliceWalker<T, W> { } } -impl<T, W> WalkerTypes for StaticSliceWalker<T, W> { - type Error = TagError<Never>; - - type Output = (); -} - impl<'ctx, T, W, E> crate::Walker<'ctx, E> for StaticSliceWalker<T, W> where E: Effect, - W: crate::Walker<'ctx, E> + WalkerTypes<Output = ()>, + W: crate::Walker<'ctx, E, Output = ()>, T: Sync, &'static T: Into<W>, { + type Error = TagError<Never>; + + type Output = (); + #[inline(always)] fn walk<'b: 'c, 'c>( self, @@ -76,7 +74,7 @@ any_trait! { impl<'ctx, T, W, E> SequenceScope<'ctx, E> for StaticSliceWalker<T, W> where E: Effect, - W: crate::Walker<'ctx, E> + WalkerTypes<Output = ()>, + W: crate::Walker<'ctx, E, Output = ()>, T: Sync, &'static T: Into<W>, { diff --git a/src/walk/walkers/core/value.rs b/src/walk/walkers/core/value.rs index 598e641..ce67f88 100644 --- a/src/walk/walkers/core/value.rs +++ b/src/walk/walkers/core/value.rs @@ -3,7 +3,6 @@ use crate::{ effect::{Effect, EffectiveExt as _, ErasedEffective}, never::Never, protocol::{visitor::visit_value, DynVisitor}, - WalkerTypes, }; /// A very basic walker that uses the [`Value`][crate::protocol::visitor::value::Value] protocol. @@ -35,13 +34,11 @@ impl<T: Copy> From<&T> for ValueWalker<T> { } } -impl<T> WalkerTypes for ValueWalker<T> { +impl<'ctx, T: Send + Sync + 'static, E: Effect> crate::Walker<'ctx, E> for ValueWalker<T> { type Error = Never; type Output = (); -} -impl<'ctx, T: Send + Sync + 'static, E: Effect> crate::Walker<'ctx, E> for ValueWalker<T> { #[inline(always)] fn walk<'b: 'c, 'c>( self, @@ -69,15 +66,13 @@ impl<'ctx, T: ?Sized> BorrowWalker<'ctx, T> { } } -impl<'ctx, T: ?Sized> WalkerTypes for BorrowWalker<'ctx, T> { +impl<'ctx, T: ?Sized + Send + Sync + 'static, E: Effect> crate::Walker<'ctx, E> + for BorrowWalker<'ctx, T> +{ type Error = Never; type Output = (); -} -impl<'ctx, T: ?Sized + Send + Sync + 'static, E: Effect> crate::Walker<'ctx, E> - for BorrowWalker<'ctx, T> -{ #[inline(always)] fn walk<'b: 'c, 'c>( self, diff --git a/src/walk/walkers/serde.rs b/src/walk/walkers/serde.rs new file mode 100644 index 0000000..218d426 --- /dev/null +++ b/src/walk/walkers/serde.rs @@ -0,0 +1 @@ +pub mod deserializer; diff --git a/src/walk/walkers/serde/deserializer.rs b/src/walk/walkers/serde/deserializer.rs new file mode 100644 index 0000000..cabffab --- /dev/null +++ b/src/walk/walkers/serde/deserializer.rs @@ -0,0 +1,15 @@ +use crate::{effect::Effect, Walker}; + +pub struct DeserializerWalker<T> { + deserializer: T, +} + +// impl<'ctx, T, E: Effect> Walker<'ctx, E> for DeserializerWalker<T> { +// +// } +// +// impl<T> WalkerTypes for DeserializerWalker<T> { +// type Error; +// +// type Output; +// } diff --git a/tests/common/walker.rs b/tests/common/walker.rs index e5f2b7c..7956a98 100644 --- a/tests/common/walker.rs +++ b/tests/common/walker.rs @@ -3,7 +3,7 @@ use treaty::{ any::{indirect, AnyTrait, AnyTraitObject, TypeNameId}, effect::{Effect, Effective, ErasedEffective}, protocol::DynVisitor, - Builder, BuilderTypes, Walker, WalkerTypes, + Builder, BuilderTypes, Walker, }; mock! { @@ -16,17 +16,13 @@ mock! { } } -impl<Output: Send + Sync, Error: Send + Sync + core::fmt::Debug> WalkerTypes +impl<'ctx, Output: Send + Sync, Error: Send + Sync + core::fmt::Debug, E: Effect> Walker<'ctx, E> for MockWalker<Output, Error> { type Error = Error; type Output = Output; -} -impl<'ctx, Output: Send + Sync, Error: Send + Sync + core::fmt::Debug, E: Effect> Walker<'ctx, E> - for MockWalker<Output, Error> -{ fn walk<'a: 'c, 'c>( self, visitor: DynVisitor<'a, 'ctx>, diff --git a/tests/walker_struct.rs b/tests/walker_struct.rs index 293ea55..6cb6e36 100644 --- a/tests/walker_struct.rs +++ b/tests/walker_struct.rs @@ -29,7 +29,7 @@ struct X { struct Info; // This gives the struct walker enough information to walk the X struct. -impl<'ctx, M> StructTypeInfo<'ctx, M> for Info { +impl<'ctx, M, E: Effect> StructTypeInfo<'ctx, M, E> for Info { const NAME: &'static str = "X"; const FIELDS: &'static [&'static str] = &["a", "b"]; @@ -40,7 +40,7 @@ impl<'ctx, M> StructTypeInfo<'ctx, M> for Info { type T = X; - fn walk_field<'a, E: Effect>( + fn walk_field<'a>( index: usize, value: &'ctx Self::T, mut visitor: DynVisitor<'a, 'ctx>, |