| 878 | |
| 879 | impl<T: ArrowNativeType> From<Vec<T>> for MutableBuffer { |
| 880 | fn from(value: Vec<T>) -> Self { |
| 881 | // Safety |
| 882 | // Vec::as_ptr guaranteed to not be null and ArrowNativeType are trivially transmutable |
| 883 | let data = unsafe { NonNull::new_unchecked(value.as_ptr() as _) }; |
| 884 | let len = value.len() * mem::size_of::<T>(); |
| 885 | // Safety |
| 886 | // Vec guaranteed to have a valid layout matching that of `Layout::array` |
| 887 | // This is based on `RawVec::current_memory` |
| 888 | let layout = unsafe { Layout::array::<T>(value.capacity()).unwrap_unchecked() }; |
| 889 | mem::forget(value); |
| 890 | Self { |
| 891 | data, |
| 892 | len, |
| 893 | layout, |
| 894 | #[cfg(feature = "pool")] |
| 895 | reservation: std::sync::Mutex::new(None), |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | impl MutableBuffer { |