Diffstat (limited to 'tests/walker_struct.rs')
| -rw-r--r-- | tests/walker_struct.rs | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/tests/walker_struct.rs b/tests/walker_struct.rs index cf09be1..160e9b0 100644 --- a/tests/walker_struct.rs +++ b/tests/walker_struct.rs @@ -1,7 +1,9 @@ +use effectful::{ + bound::ForceDynamic, effective::Effective, environment::{Environment, NativeForm}, is_send_sync +}; use mockall::predicate::eq; use treaty::{ any::{BorrowedStatic, BorrowedStaticHrt, OwnedStatic, StaticType, TypeNameId}, - effect::{blocking::Blocking, Effect, Effective, ErasedEffective}, protocol::{ visitor::{tags, SequenceProto, TagConst, TagProto, ValueProto, VisitResult}, AsVisitor, DynVisitor, @@ -13,6 +15,7 @@ use treaty::{ use crate::common::{ builder::{EmptyError, MockBuilder}, protocol::{sequence::MockSequenceVisitor, tag::MockTagVisitor, value::MockValueVisitor}, + Blocking, }; mod common; @@ -22,10 +25,12 @@ struct X { b: i32, } +is_send_sync!(X); + struct Info; // This gives the struct walker enough information to walk the X struct. -impl<'ctx, M, E: Effect> StructTypeInfo<'ctx, M, E> for Info { +impl<'ctx, M, E: Environment> StructTypeInfo<'ctx, M, E> for Info { const NAME: &'static str = "X"; const FIELDS: &'static [&'static str] = &["a", "b"]; @@ -39,9 +44,9 @@ impl<'ctx, M, E: Effect> StructTypeInfo<'ctx, M, E> for Info { fn walk_field<'a>( index: usize, value: &'ctx Self::T, - mut visitor: DynVisitor<'a, 'ctx>, - ) -> ErasedEffective<'a, Result<Flow, Self::FieldError>, E> { - E::from_future(async move { + mut visitor: DynVisitor<'a, 'ctx, E>, + ) -> NativeForm<'a, Result<Flow, Self::FieldError>, E> { + E::future(unsafe { ForceDynamic::new(async move { match index { // A real impl would be expected to tag these values with the field name. 0 => { @@ -76,7 +81,8 @@ impl<'ctx, M, E: Effect> StructTypeInfo<'ctx, M, E> for Info { } _ => Ok(Flow::Done), } - }) + })}) + .cast() } } @@ -92,32 +98,33 @@ fn sequence_of_field_values() { // The struct walker using the info we provided about the struct. let walker = StructWalker::<Info, _, DefaultMode, Blocking>::new(&value); - let mut builder = MockBuilder::<(), (), EmptyError>::new(); + let mut builder = MockBuilder::<(), (), EmptyError, Blocking>::new(); // Expect a visit on the sequence protocol for the struct fields. builder .expect_traits_mut() .once() - .with(eq(TypeNameId::of::<SequenceProto<Blocking>>())) + .with(eq(TypeNameId::of::<SequenceProto<Blocking>, Blocking>())) .returning(|_| { let mut visitor = MockSequenceVisitor::<Blocking>::new(); // Expect the sequence visitor to be used. visitor.expect_visit().once().returning(|scope| { // The struct should have exactly 2 fields. - assert_eq!(scope.size_hint().value(), (2, Some(2))); + assert_eq!(scope.size_hint().into_value(), (2, Some(2))); // Get the first field value. { - let mut visitor = MockBuilder::<(), (), EmptyError>::new(); + let mut visitor = MockBuilder::<(), (), EmptyError, Blocking>::new(); // Expect a bool value for the field. visitor .expect_traits_mut() .once() - .with(eq( - TypeNameId::of::<ValueProto<OwnedStatic<bool>, Blocking>>(), - )) + .with(eq(TypeNameId::of::< + ValueProto<OwnedStatic<bool>, Blocking>, + Blocking, + >())) .returning(|_| { let mut visitor = MockValueVisitor::<OwnedStatic<bool>, Blocking>::new(); @@ -133,21 +140,21 @@ fn sequence_of_field_values() { }); assert_eq!( - scope.next(AsVisitor::as_visitor(&mut visitor)).value(), + scope.next(AsVisitor::as_visitor(&mut visitor)).into_value(), Flow::Continue ); } // Get the second field value. { - let mut visitor = MockBuilder::<(), (), EmptyError>::new(); + let mut visitor = MockBuilder::<(), (), EmptyError, Blocking>::new(); // Expect a i32 value. visitor .expect_traits_mut() .once() .with(eq( - TypeNameId::of::<ValueProto<OwnedStatic<i32>, Blocking>>(), + TypeNameId::of::<ValueProto<OwnedStatic<i32>, Blocking>, Blocking>(), )) .returning(|_| { let mut visitor = MockValueVisitor::<OwnedStatic<i32>, Blocking>::new(); @@ -163,7 +170,7 @@ fn sequence_of_field_values() { }); assert_eq!( - scope.next(AsVisitor::as_visitor(&mut visitor)).value(), + scope.next(AsVisitor::as_visitor(&mut visitor)).into_value(), Flow::Done ); } @@ -180,7 +187,7 @@ fn sequence_of_field_values() { // Walk the struct. assert_eq!( - walker.walk(AsVisitor::as_visitor(&mut builder)).value(), + walker.walk(AsVisitor::as_visitor(&mut builder)).into_value(), Ok(()) ); } @@ -193,7 +200,7 @@ fn has_struct_tag() { // The struct walker using the info we provided about the struct. let walker = StructWalker::<Info, _, DefaultMode, Blocking>::new(&value); - let mut builder = MockBuilder::<(), (), EmptyError>::new(); + let mut builder = MockBuilder::<(), (), EmptyError, Blocking>::new(); let mut seq = mockall::Sequence::new(); @@ -209,15 +216,15 @@ fn has_struct_tag() { .expect_traits_mut() .once() .in_sequence(&mut seq) - .with(eq(TypeNameId::of::<TagProto<tags::Struct, Blocking>>())) + .with(eq(TypeNameId::of::<TagProto<tags::Struct, Blocking>, Blocking>())) .returning(|_| { let mut visitor = MockTagVisitor::<tags::Struct, Blocking>::new(); visitor.expect_visit().once().returning(|TagConst, walker| { - let mut visitor = MockBuilder::<(), (), ()>::new(); + let mut visitor = MockBuilder::<(), (), (), Blocking>::new(); // Walk the noop walker so there isn't an error. - assert_eq!(walker.walk(DynVisitor(&mut visitor)).value(), Flow::Done); + assert_eq!(walker.walk(DynVisitor(&mut visitor)).into_value(), Flow::Done); // We are done, the walker should now stop early. VisitResult::Control(Flow::Done) @@ -228,7 +235,7 @@ fn has_struct_tag() { // Walk the struct. assert_eq!( - walker.walk(AsVisitor::as_visitor(&mut builder)).value(), + walker.walk(AsVisitor::as_visitor(&mut builder)).into_value(), Ok(()) ); } @@ -241,7 +248,7 @@ fn has_map_backup_tag() { // The struct walker using the info we provided about the struct. let walker = StructWalker::<Info, _, DefaultMode, Blocking>::new(&value); - let mut builder = MockBuilder::<(), (), EmptyError>::new(); + let mut builder = MockBuilder::<(), (), EmptyError, Blocking>::new(); let mut seq = mockall::Sequence::new(); @@ -259,15 +266,15 @@ fn has_map_backup_tag() { .expect_traits_mut() .once() .in_sequence(&mut seq) - .with(eq(TypeNameId::of::<TagProto<tags::Map, Blocking>>())) + .with(eq(TypeNameId::of::<TagProto<tags::Map, Blocking>, Blocking>())) .returning(|_| { let mut visitor = MockTagVisitor::<tags::Map, Blocking>::new(); visitor.expect_visit().once().returning(|TagConst, walker| { - let mut visitor = MockBuilder::<(), (), ()>::new(); + let mut visitor = MockBuilder::<(), (), (), Blocking>::new(); // Walk the noop walker so there isn't an error. - assert_eq!(walker.walk(DynVisitor(&mut visitor)).value(), Flow::Done); + assert_eq!(walker.walk(DynVisitor(&mut visitor)).into_value(), Flow::Done); // We are done, the walker should now stop early. VisitResult::Control(Flow::Done) @@ -278,7 +285,7 @@ fn has_map_backup_tag() { // Walk the struct. assert_eq!( - walker.walk(AsVisitor::as_visitor(&mut builder)).value(), + walker.walk(AsVisitor::as_visitor(&mut builder)).into_value(), Ok(()) ); } @@ -291,7 +298,7 @@ fn borrowed_value_directly() { // The struct walker using the info we provided about the struct. let walker = StructWalker::<Info, _, DefaultMode, Blocking>::new(&value); - let mut builder = MockBuilder::<(), (), EmptyError>::new(); + let mut builder = MockBuilder::<(), (), EmptyError, Blocking>::new(); let mut seq = mockall::Sequence::new(); @@ -308,7 +315,7 @@ fn borrowed_value_directly() { .once() .in_sequence(&mut seq) .with(eq(TypeNameId::of::< - ValueProto<BorrowedStaticHrt<X>, Blocking>, + ValueProto<BorrowedStaticHrt<X>, Blocking>, Blocking >())) .returning(|_| { let mut visitor = MockValueVisitor::<BorrowedStaticHrt<X>, Blocking>::new(); @@ -331,7 +338,7 @@ fn borrowed_value_directly() { // Walk the struct. assert_eq!( - walker.walk(AsVisitor::as_visitor(&mut builder)).value(), + walker.walk(AsVisitor::as_visitor(&mut builder)).into_value(), Ok(()) ); } |