MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / as_mut_slice

Method as_mut_slice

src/buffer.rs:347–363  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

readonlyMethod · 0.80
item_sizeMethod · 0.80
is_c_contiguousMethod · 0.80
formatMethod · 0.80
item_countMethod · 0.80

Tested by

no test coverage detected