MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_import

Function test_import

arrow-array/src/ffi.rs:616–639  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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<()> {

Callers

nothing calls this directly

Calls 3

from_ffiFunction · 0.85
into_dataMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected