| 614 | |
| 615 | #[test] |
| 616 | fn test_import() { |
| 617 | // Model receiving const pointers from an external system |
| 618 | |
| 619 | // Create an array natively |
| 620 | let data = Int32Array::from(vec![1, 2, 3]).into_data(); |
| 621 | let schema = FFI_ArrowSchema::try_from(data.data_type()).unwrap(); |
| 622 | let array = FFI_ArrowArray::new(&data); |
| 623 | |
| 624 | // Use ManuallyDrop to avoid Box:Drop recursing |
| 625 | let schema = Box::new(ManuallyDrop::new(schema)); |
| 626 | let array = Box::new(ManuallyDrop::new(array)); |
| 627 | |
| 628 | let schema_ptr = &**schema as *const _; |
| 629 | let array_ptr = &**array as *const _; |
| 630 | |
| 631 | // We can read them back to memory |
| 632 | // SAFETY: |
| 633 | // Pointers are aligned and valid |
| 634 | let data = |
| 635 | unsafe { from_ffi(std::ptr::read(array_ptr), &std::ptr::read(schema_ptr)).unwrap() }; |
| 636 | |
| 637 | let array = Int32Array::from(data); |
| 638 | assert_eq!(array, Int32Array::from(vec![1, 2, 3])); |
| 639 | } |
| 640 | |
| 641 | #[test] |
| 642 | fn test_round_trip_with_offset() -> Result<()> { |