MCPcopy Index your code
hub / github.com/PyO3/rust-numpy / as_slice_mut

Method as_slice_mut

src/array.rs:776–791  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

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 ///

Callers

nothing calls this directly

Implementers 1

array.rssrc/array.rs

Calls 4

lenMethod · 0.80
is_alignedMethod · 0.80
is_contiguousMethod · 0.80
dataMethod · 0.80

Tested by

no test coverage detected