Diffstat (limited to 'src/walk/walkers/core/int.rs')
| -rw-r--r-- | src/walk/walkers/core/int.rs | 96 |
1 files changed, 74 insertions, 22 deletions
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() |