(&self)
| 774 | /// Please consider the safe alternative [`PyReadwriteArray::as_slice_mut`]. |
| 775 | #[allow(clippy::mut_from_ref)] |
| 776 | unsafe fn as_slice_mut(&self) -> Result<&mut [T], AsSliceError> |
| 777 | where |
| 778 | T: Element, |
| 779 | D: Dimension, |
| 780 | { |
| 781 | let len = self.len(); |
| 782 | if len == 0 { |
| 783 | // We can still produce a slice over zero objects regardless of whether |
| 784 | // the underlying pointer is aligned or not. |
| 785 | Ok(&mut []) |
| 786 | } else if self.is_aligned() && self.is_contiguous() { |
| 787 | Ok(slice::from_raw_parts_mut(self.data(), len)) |
| 788 | } else { |
| 789 | Err(AsSliceError) |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | /// Get a reference of the specified element if the given index is valid. |
| 794 | /// |
nothing calls this directly
no test coverage detected