Gets the buffer memory as a slice. This function succeeds if: the buffer is not read-only the buffer format is compatible with `T` alignment and size of buffer elements is matching the expectations for type `T` the buffer is C-style contiguous The returned slice uses type `Cell ` because it's theoretically possible for any call into the Python runtime to modify the values in the slice.
(&'a self, _py: Python<'a>)
| 345 | /// The returned slice uses type `Cell<T>` because it's theoretically possible for any call into the Python runtime |
| 346 | /// to modify the values in the slice. |
| 347 | pub fn as_mut_slice<'a, T: Element>(&'a self, _py: Python<'a>) -> Option<&'a [cell::Cell<T>]> { |
| 348 | if !self.readonly() |
| 349 | && mem::size_of::<T>() == self.item_size() |
| 350 | && (self.0.buf as usize) % mem::align_of::<T>() == 0 |
| 351 | && self.is_c_contiguous() |
| 352 | && T::is_compatible_format(self.format()) |
| 353 | { |
| 354 | unsafe { |
| 355 | Some(slice::from_raw_parts( |
| 356 | self.0.buf as *mut cell::Cell<T>, |
| 357 | self.item_count(), |
| 358 | )) |
| 359 | } |
| 360 | } else { |
| 361 | None |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /// Gets the buffer memory as a slice. |
| 366 | /// |
nothing calls this directly
no test coverage detected