()
| 894 | |
| 895 | #[test] |
| 896 | fn test_vec_interop() { |
| 897 | // Test empty vec |
| 898 | let a: Vec<i128> = Vec::new(); |
| 899 | let b = Buffer::from_vec(a); |
| 900 | b.into_vec::<i128>().unwrap(); |
| 901 | |
| 902 | // Test vec with capacity |
| 903 | let a: Vec<i128> = Vec::with_capacity(20); |
| 904 | let b = Buffer::from_vec(a); |
| 905 | let back = b.into_vec::<i128>().unwrap(); |
| 906 | assert_eq!(back.len(), 0); |
| 907 | assert_eq!(back.capacity(), 20); |
| 908 | |
| 909 | // Test vec with values |
| 910 | let mut a: Vec<i128> = Vec::with_capacity(3); |
| 911 | a.extend_from_slice(&[1, 2, 3]); |
| 912 | let b = Buffer::from_vec(a); |
| 913 | let back = b.into_vec::<i128>().unwrap(); |
| 914 | assert_eq!(back.len(), 3); |
| 915 | assert_eq!(back.capacity(), 3); |
| 916 | |
| 917 | // Test vec with values and spare capacity |
| 918 | let mut a: Vec<i128> = Vec::with_capacity(20); |
| 919 | a.extend_from_slice(&[1, 4, 7, 8, 9, 3, 6]); |
| 920 | let b = Buffer::from_vec(a); |
| 921 | let back = b.into_vec::<i128>().unwrap(); |
| 922 | assert_eq!(back.len(), 7); |
| 923 | assert_eq!(back.capacity(), 20); |
| 924 | |
| 925 | // Test incorrect alignment |
| 926 | let a: Vec<i128> = Vec::new(); |
| 927 | let b = Buffer::from_vec(a); |
| 928 | let b = b.into_vec::<i32>().unwrap_err(); |
| 929 | b.into_vec::<i8>().unwrap_err(); |
| 930 | |
| 931 | // Test convert between types with same alignment |
| 932 | // This is an implementation quirk, but isn't harmful |
| 933 | // as ArrowNativeType are trivially transmutable |
| 934 | let a: Vec<i64> = vec![1, 2, 3, 4]; |
| 935 | let b = Buffer::from_vec(a); |
| 936 | let back = b.into_vec::<u64>().unwrap(); |
| 937 | assert_eq!(back.len(), 4); |
| 938 | assert_eq!(back.capacity(), 4); |
| 939 | |
| 940 | // i256 has the same layout as i128 so this is valid |
| 941 | let mut b: Vec<i128> = Vec::with_capacity(4); |
| 942 | b.extend_from_slice(&[1, 2, 3, 4]); |
| 943 | let b = Buffer::from_vec(b); |
| 944 | let back = b.into_vec::<i256>().unwrap(); |
| 945 | assert_eq!(back.len(), 2); |
| 946 | assert_eq!(back.capacity(), 2); |
| 947 | |
| 948 | // Invalid layout |
| 949 | let b: Vec<i128> = vec![1, 2, 3]; |
| 950 | let b = Buffer::from_vec(b); |
| 951 | b.into_vec::<i256>().unwrap_err(); |
| 952 | |
| 953 | // Invalid layout |
nothing calls this directly
no test coverage detected