| 49 | type Dim = Ix1; |
| 50 | |
| 51 | fn into_pyarray<'py>(self, py: Python<'py>) -> Bound<'py, PyArray<Self::Item, Self::Dim>> { |
| 52 | let container = PySliceContainer::from(self); |
| 53 | let dims = Dim([container.len]); |
| 54 | let strides = [mem::size_of::<T>() as npy_intp]; |
| 55 | // The data pointer is derived only after dissolving `Box` into `PySliceContainer` |
| 56 | // to avoid unsound aliasing of Box<[T]> which is currently noalias, |
| 57 | // c.f. https://github.com/rust-lang/unsafe-code-guidelines/issues/326 |
| 58 | let data_ptr = container.ptr as *mut T; |
| 59 | unsafe { PyArray::from_raw_parts(py, dims, strides.as_ptr(), data_ptr, container) } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | impl<T: Element> IntoPyArray for Vec<T> { |