Gets the buffer memory as a slice. This function succeeds if: 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>)
| 318 | /// The returned slice uses type `Cell<T>` because it's theoretically possible for any call into the Python runtime |
| 319 | /// to modify the values in the slice. |
| 320 | pub fn as_slice<'a, T: Element>(&'a self, _py: Python<'a>) -> Option<&'a [ReadOnlyCell<T>]> { |
| 321 | if mem::size_of::<T>() == self.item_size() |
| 322 | && (self.0.buf as usize) % mem::align_of::<T>() == 0 |
| 323 | && self.is_c_contiguous() |
| 324 | && T::is_compatible_format(self.format()) |
| 325 | { |
| 326 | unsafe { |
| 327 | Some(slice::from_raw_parts( |
| 328 | self.0.buf as *mut ReadOnlyCell<T>, |
| 329 | self.item_count(), |
| 330 | )) |
| 331 | } |
| 332 | } else { |
| 333 | None |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /// Gets the buffer memory as a slice. |
| 338 | /// |
nothing calls this directly
no test coverage detected