pub struct PyUntypedBufferView<Flags: PyBufferFlagsType = PyBufferFlags> { /* private fields */ }Expand description
Stack-allocated untyped buffer view.
Unlike PyUntypedBuffer which heap-allocates, this places the Py_buffer on the
stack. The scoped closure API ensures the buffer cannot be moved.
Use with_flags() with a PyBufferFlags value to acquire a view.
The available accessors depend on the flags used.
Implementations§
Source§impl<Flags: PyBufferFlagsType> PyUntypedBufferView<Flags>
impl<Flags: PyBufferFlagsType> 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.
Source§impl<const SHAPE: bool, const STRIDE: bool, const WRITABLE: bool, const CONTIGUITY: u8> PyUntypedBufferView<PyBufferFlags<true, SHAPE, STRIDE, WRITABLE, CONTIGUITY>>
impl<const SHAPE: bool, const STRIDE: bool, const WRITABLE: bool, const CONTIGUITY: u8> PyUntypedBufferView<PyBufferFlags<true, SHAPE, STRIDE, WRITABLE, CONTIGUITY>>
Sourcepub fn format(&self) -> &CStr
pub fn format(&self) -> &CStr
A struct module style string describing the contents of a single item.
Sourcepub fn as_typed<T: Element>(
&self,
) -> PyResult<&PyBufferView<T, PyBufferFlags<true, SHAPE, STRIDE, WRITABLE, CONTIGUITY>>>
pub fn as_typed<T: Element>( &self, ) -> PyResult<&PyBufferView<T, PyBufferFlags<true, SHAPE, STRIDE, WRITABLE, CONTIGUITY>>>
Attempt to interpret this untyped view as containing elements of type T.
Source§impl<const FORMAT: bool, const STRIDE: bool, const WRITABLE: bool, const CONTIGUITY: u8> PyUntypedBufferView<PyBufferFlags<FORMAT, true, STRIDE, WRITABLE, CONTIGUITY>>
impl<const FORMAT: bool, const STRIDE: bool, const WRITABLE: bool, const CONTIGUITY: u8> PyUntypedBufferView<PyBufferFlags<FORMAT, true, STRIDE, WRITABLE, CONTIGUITY>>
Source§impl<const FORMAT: bool, const SHAPE: bool, const WRITABLE: bool, const CONTIGUITY: u8> PyUntypedBufferView<PyBufferFlags<FORMAT, SHAPE, true, WRITABLE, CONTIGUITY>>
impl<const FORMAT: bool, const SHAPE: bool, const WRITABLE: bool, const CONTIGUITY: u8> PyUntypedBufferView<PyBufferFlags<FORMAT, SHAPE, true, WRITABLE, CONTIGUITY>>
Source§impl<const WRITABLE: bool> PyUntypedBufferView<PyBufferFlags<false, false, false, WRITABLE, CONTIGUITY_UNDEFINED>>
impl<const WRITABLE: bool> PyUntypedBufferView<PyBufferFlags<false, false, false, WRITABLE, CONTIGUITY_UNDEFINED>>
Source§impl PyUntypedBufferView
impl PyUntypedBufferView
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(&PyUntypedBufferView<PyBufferFlags<FORMAT, 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(&PyUntypedBufferView<PyBufferFlags<FORMAT, SHAPE, STRIDE, WRITABLE, CONTIGUITY>>) -> R, ) -> PyResult<R>
Acquire a buffer view with the given flags,
pass it to f, then release the buffer.
Use PyBufferFlags::simple() or one of the compound-request constructors such as
PyBufferFlags::full_ro() to acquire a view.
Trait Implementations§
Source§impl<Flags: PyBufferFlagsType> Debug for PyUntypedBufferView<Flags>
impl<Flags: PyBufferFlagsType> Debug for PyUntypedBufferView<Flags>
Source§impl<Flags: PyBufferFlagsType> Drop for PyUntypedBufferView<Flags>
impl<Flags: PyBufferFlagsType> Drop for PyUntypedBufferView<Flags>
Auto Trait Implementations§
impl<Flags> Freeze for PyUntypedBufferView<Flags>
impl<Flags> RefUnwindSafe for PyUntypedBufferView<Flags>where
Flags: RefUnwindSafe,
impl<Flags = PyBufferFlags> !Send for PyUntypedBufferView<Flags>
impl<Flags = PyBufferFlags> !Sync for PyUntypedBufferView<Flags>
impl<Flags> Unpin for PyUntypedBufferView<Flags>where
Flags: Unpin,
impl<Flags> UnsafeUnpin for PyUntypedBufferView<Flags>
impl<Flags> UnwindSafe for PyUntypedBufferView<Flags>where
Flags: 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