| 701 | |
| 702 | #[test] |
| 703 | fn can_put_funcrefs_in_structs() -> Result<()> { |
| 704 | let mut store = gc_store()?; |
| 705 | |
| 706 | let struct_ty = StructType::new( |
| 707 | store.engine(), |
| 708 | [FieldType::new(Mutability::Var, RefType::FUNCREF.into())], |
| 709 | )?; |
| 710 | |
| 711 | let f0 = Func::wrap(&mut store, |_caller: Caller<()>| -> u32 { 0x1234 }); |
| 712 | let f1 = Func::wrap(&mut store, |_caller: Caller<()>| -> u32 { 0x5678 }); |
| 713 | |
| 714 | let pre = StructRefPre::new(&mut store, struct_ty.clone()); |
| 715 | let s = StructRef::new(&mut store, &pre, &[f0.into()])?; |
| 716 | |
| 717 | let f = s.field(&mut store, 0)?; |
| 718 | let f = f.unwrap_funcref().unwrap(); |
| 719 | let f = f.typed::<(), u32>(&store)?; |
| 720 | assert_eq!(f.call(&mut store, ())?, 0x1234); |
| 721 | |
| 722 | s.set_field(&mut store, 0, f1.into())?; |
| 723 | |
| 724 | let f = s.field(&mut store, 0)?; |
| 725 | let f = f.unwrap_funcref().unwrap(); |
| 726 | let f = f.typed::<(), u32>(&store)?; |
| 727 | assert_eq!(f.call(&mut store, ())?, 0x5678); |
| 728 | |
| 729 | Ok(()) |
| 730 | } |
| 731 | |
| 732 | #[test] |
| 733 | #[cfg_attr(miri, ignore)] |