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

Function test_from_foreign_vec

arrow-buffer/src/buffer/immutable.rs:869–886  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

867
868 #[test]
869 fn test_from_foreign_vec() {
870 let mut vector = vec![1_i32, 2, 3, 4, 5];
871 let buffer = unsafe {
872 Buffer::from_custom_allocation(
873 NonNull::new_unchecked(vector.as_mut_ptr() as *mut u8),
874 vector.len() * std::mem::size_of::<i32>(),
875 Arc::new(vector),
876 )
877 };
878
879 let slice = buffer.typed_data::<i32>();
880 assert_eq!(slice, &[1, 2, 3, 4, 5]);
881
882 let buffer = buffer.slice(std::mem::size_of::<i32>());
883
884 let slice = buffer.typed_data::<i32>();
885 assert_eq!(slice, &[2, 3, 4, 5]);
886 }
887
888 #[test]
889 #[should_panic(expected = "the offset of the new Buffer cannot exceed the existing length")]

Callers

nothing calls this directly

Calls 3

as_mut_ptrMethod · 0.80
lenMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected