pub struct PyBufferView<T, Flags: PyBufferFlagsType = PyBufferFlags<true, true, true>>(/* private fields */);Expand description
A typed form of PyUntypedBufferView. Not constructible directly — use
PyBufferView::with() or PyBufferView::with_flags().
Implementations§
Source§impl<T: Element> PyBufferView<T>
impl<T: Element> PyBufferView<T>
Sourcepub fn with<R>(
obj: &Bound<'_, PyAny>,
f: impl FnOnce(&PyBufferView<T>) -> R,
) -> PyResult<R>
pub fn with<R>( obj: &Bound<'_, PyAny>, f: impl FnOnce(&PyBufferView<T>) -> R, ) -> PyResult<R>
Acquire a typed buffer view with PyBufferFlags::full_ro() flags,
validating that the buffer format is compatible with T.
Sourcepub fn with_flags<const FORMAT: bool, const SHAPE: bool, const STRIDE: bool, const WRITABLE: bool, const CONTIGUITY: u8, R>(
obj: &Bound<'_, PyAny>,
flags: PyBufferFlags<FORMAT, SHAPE, STRIDE, WRITABLE, CONTIGUITY>,
f: impl FnOnce(&PyBufferView<T, PyBufferFlags<true, SHAPE, STRIDE, WRITABLE, CONTIGUITY>>) -> R,
) -> PyResult<R>
pub fn with_flags<const FORMAT: bool, const SHAPE: bool, const STRIDE: bool, const WRITABLE: bool, const CONTIGUITY: u8, R>( obj: &Bound<'_, PyAny>, flags: PyBufferFlags<FORMAT, SHAPE, STRIDE, WRITABLE, CONTIGUITY>, f: impl FnOnce(&PyBufferView<T, PyBufferFlags<true, SHAPE, STRIDE, WRITABLE, CONTIGUITY>>) -> R, ) -> PyResult<R>
Acquire a typed buffer view with the given flags.
ffi::PyBUF_FORMAT is implicitly added for type validation.
Source§impl<T: Element, Flags: PyBufferFlagsType> PyBufferView<T, Flags>
impl<T: Element, Flags: PyBufferFlagsType> PyBufferView<T, Flags>
Sourcepub fn as_slice<'a>(&'a self, _py: Python<'a>) -> Option<&'a [ReadOnlyCell<T>]>
pub fn as_slice<'a>(&'a self, _py: Python<'a>) -> Option<&'a [ReadOnlyCell<T>]>
Gets the buffer memory as a slice.
Returns None if the buffer is not C-contiguous.
The returned slice uses type ReadOnlyCell<T> because it’s theoretically possible
for any call into the Python runtime to modify the values in the slice.
Sourcepub fn as_mut_slice<'a>(&'a self, _py: Python<'a>) -> Option<&'a [Cell<T>]>
pub fn as_mut_slice<'a>(&'a self, _py: Python<'a>) -> Option<&'a [Cell<T>]>
Gets the buffer memory as a mutable slice.
Returns None if the buffer is read-only or not C-contiguous.
The returned slice uses type Cell<T> because it’s theoretically possible
for any call into the Python runtime to modify the values in the slice.
Source§impl<T: Element, const FORMAT: bool, const SHAPE: bool, const STRIDE: bool, const WRITABLE: bool> PyBufferView<T, PyBufferFlags<FORMAT, SHAPE, STRIDE, WRITABLE, CONTIGUITY_C>>
impl<T: Element, const FORMAT: bool, const SHAPE: bool, const STRIDE: bool, const WRITABLE: bool> PyBufferView<T, PyBufferFlags<FORMAT, SHAPE, STRIDE, WRITABLE, CONTIGUITY_C>>
Sourcepub fn as_contiguous_slice<'a>(
&'a self,
_py: Python<'a>,
) -> &'a [ReadOnlyCell<T>]
pub fn as_contiguous_slice<'a>( &'a self, _py: Python<'a>, ) -> &'a [ReadOnlyCell<T>]
Gets the buffer memory as a slice. The buffer is guaranteed C-contiguous.
Source§impl<T: Element, const FORMAT: bool, const SHAPE: bool, const STRIDE: bool> PyBufferView<T, PyBufferFlags<FORMAT, SHAPE, STRIDE, true, CONTIGUITY_C>>
impl<T: Element, const FORMAT: bool, const SHAPE: bool, const STRIDE: bool> PyBufferView<T, PyBufferFlags<FORMAT, SHAPE, STRIDE, true, CONTIGUITY_C>>
Sourcepub fn as_contiguous_mut_slice<'a>(&'a self, _py: Python<'a>) -> &'a [Cell<T>]
pub fn as_contiguous_mut_slice<'a>(&'a self, _py: Python<'a>) -> &'a [Cell<T>]
Gets the buffer memory as a mutable slice. The buffer is guaranteed C-contiguous and writable.
Source§impl<T: Element, const FORMAT: bool, const SHAPE: bool, const STRIDE: bool, const WRITABLE: bool> PyBufferView<T, PyBufferFlags<FORMAT, SHAPE, STRIDE, WRITABLE, CONTIGUITY_F>>
impl<T: Element, const FORMAT: bool, const SHAPE: bool, const STRIDE: bool, const WRITABLE: bool> PyBufferView<T, PyBufferFlags<FORMAT, SHAPE, STRIDE, WRITABLE, CONTIGUITY_F>>
Sourcepub fn as_fortran_contiguous_slice<'a>(
&'a self,
_py: Python<'a>,
) -> &'a [ReadOnlyCell<T>]
pub fn as_fortran_contiguous_slice<'a>( &'a self, _py: Python<'a>, ) -> &'a [ReadOnlyCell<T>]
Gets the buffer memory as a slice. The buffer is guaranteed Fortran-contiguous.
Source§impl<T: Element, const FORMAT: bool, const SHAPE: bool, const STRIDE: bool> PyBufferView<T, PyBufferFlags<FORMAT, SHAPE, STRIDE, true, CONTIGUITY_F>>
impl<T: Element, const FORMAT: bool, const SHAPE: bool, const STRIDE: bool> PyBufferView<T, PyBufferFlags<FORMAT, SHAPE, STRIDE, true, CONTIGUITY_F>>
Sourcepub fn as_fortran_contiguous_mut_slice<'a>(
&'a self,
_py: Python<'a>,
) -> &'a [Cell<T>]
pub fn as_fortran_contiguous_mut_slice<'a>( &'a self, _py: Python<'a>, ) -> &'a [Cell<T>]
Gets the buffer memory as a mutable slice. The buffer is guaranteed Fortran-contiguous and writable.
Methods from Deref<Target = PyUntypedBufferView<Flags>>§
Sourcepub fn obj<'py>(&self, py: Python<'py>) -> Option<&Bound<'py, PyAny>>
pub fn obj<'py>(&self, py: Python<'py>) -> Option<&Bound<'py, PyAny>>
Returns the Python object that owns the buffer data.
Sourcepub fn item_count(&self) -> usize
pub fn item_count(&self) -> usize
Gets the total number of items.
Sourcepub fn len_bytes(&self) -> usize
pub fn len_bytes(&self) -> usize
item_size() * item_count().
For contiguous arrays, this is the length of the underlying memory block.
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Gets the number of dimensions.
May be 0 to indicate a single scalar value.
Sourcepub fn suboffsets(&self) -> Option<&[isize]>
pub fn suboffsets(&self) -> Option<&[isize]>
Returns the suboffsets array.
May return None even with PyBUF_INDIRECT if the exporter sets suboffsets to NULL.
Sourcepub fn is_c_contiguous(&self) -> bool
pub fn is_c_contiguous(&self) -> bool
Gets whether the buffer is contiguous in C-style order.
Sourcepub fn is_fortran_contiguous(&self) -> bool
pub fn is_fortran_contiguous(&self) -> bool
Gets whether the buffer is contiguous in Fortran-style order.
Trait Implementations§
Source§impl<T, Flags: PyBufferFlagsType> Debug for PyBufferView<T, Flags>
impl<T, Flags: PyBufferFlagsType> Debug for PyBufferView<T, Flags>
Source§impl<T, Flags: PyBufferFlagsType> Deref for PyBufferView<T, Flags>
impl<T, Flags: PyBufferFlagsType> Deref for PyBufferView<T, Flags>
Auto Trait Implementations§
impl<T, Flags> Freeze for PyBufferView<T, Flags>
impl<T, Flags> RefUnwindSafe for PyBufferView<T, Flags>where
Flags: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, Flags = PyBufferFlags<true, true, true>> !Send for PyBufferView<T, Flags>
impl<T, Flags = PyBufferFlags<true, true, true>> !Sync for PyBufferView<T, Flags>
impl<T, Flags> Unpin for PyBufferView<T, Flags>
impl<T, Flags> UnsafeUnpin for PyBufferView<T, Flags>
impl<T, Flags> UnwindSafe for PyBufferView<T, Flags>where
Flags: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more