#[repr(transparent)]pub struct PyUntypedBufferView<Flag: PyBufferRequestType = PyBufferFlags<false, false, false, false, false, CONTIGUITY_UNDEFINED>> {
raw: Py_buffer,
_flags: PhantomData<Flag>,
_pin: PhantomPinned,
}Py_3_11 or non-Py_LIMITED_API only.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 PyBufferRequest value to acquire a view.
The available accessors depend on the flags used.
Fields§
§raw: Py_buffer§_flags: PhantomData<Flag>§_pin: PhantomPinnedImplementations§
Source§impl<Flag: PyBufferRequestType> PyUntypedBufferView<Flag>
impl<Flag: PyBufferRequestType> PyUntypedBufferView<Flag>
Sourcepub fn buf_ptr(&self) -> *mut c_void
pub fn buf_ptr(&self) -> *mut c_void
Gets the pointer to the start of the buffer memory.
See PyUntypedBuffer::buf_ptr() for considerations about how
to safely read and write data through this pointer.
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.
Always at least 1. Scalar buffers are rejected during acquisition.
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<Flag: PyBufferRequestType> PyUntypedBufferView<Flag>
impl<Flag: PyBufferRequestType> PyUntypedBufferView<Flag>
Sourcepub fn format(&self) -> &CStrwhere
Flag: IncludesFormat,
pub fn format(&self) -> &CStrwhere
Flag: IncludesFormat,
A struct module style string describing the contents of a single item.
Sourcepub fn as_typed<T: Element>(&self) -> PyResult<&PyBufferView<T, Flag>>where
Flag: IncludesFormat,
pub fn as_typed<T: Element>(&self) -> PyResult<&PyBufferView<T, Flag>>where
Flag: IncludesFormat,
Attempt to interpret this untyped view as containing elements of type T.
fn ensure_compatible_with<T: Element>(&self) -> PyResult<()>where
Flag: IncludesFormat,
Sourcepub fn shape(&self) -> &[usize]where
Flag: IncludesShape,
pub fn shape(&self) -> &[usize]where
Flag: IncludesShape,
Returns the shape array. shape[i] is the length of dimension i.
Despite Python using an array of signed integers, the values are guaranteed to be non-negative. However, dimensions of length 0 are possible and might need special attention.
Sourcepub fn strides(&self) -> &[isize]where
Flag: IncludesStrides,
pub fn strides(&self) -> &[isize]where
Flag: IncludesStrides,
Returns the strides array.
Stride values can be any integer. For regular arrays, strides are usually positive,
but a consumer MUST be able to handle the case strides[n] <= 0.
Sourcepub fn suboffsets(&self) -> Option<&[isize]>where
Flag: IncludesSuboffsets,
pub fn suboffsets(&self) -> Option<&[isize]>where
Flag: IncludesSuboffsets,
Returns the suboffsets array.
May return None even when suboffsets were requested if the exporter sets
suboffsets to NULL.
Source§impl PyUntypedBufferView
impl PyUntypedBufferView
Sourcepub fn with_flags<Flag: PyBufferRequestType, R>(
obj: &Bound<'_, PyAny>,
flags: PyBufferRequest<Flag>,
f: impl FnOnce(&PyUntypedBufferView<Flag>) -> R,
) -> PyResult<R>
pub fn with_flags<Flag: PyBufferRequestType, R>( obj: &Bound<'_, PyAny>, flags: PyBufferRequest<Flag>, f: impl FnOnce(&PyUntypedBufferView<Flag>) -> R, ) -> PyResult<R>
Acquire a buffer view with the given flags,
pass it to f, then release the buffer.
Use PyBufferRequest::simple() or one of the compound-request constructors such as
PyBufferRequest::full_ro() to acquire a view.
The requested flags constrain what exporters may return. For example, without shape information only 1-dimensional buffers are permitted.
Trait Implementations§
Source§impl<Flag: PyBufferRequestType> Debug for PyUntypedBufferView<Flag>
impl<Flag: PyBufferRequestType> Debug for PyUntypedBufferView<Flag>
Source§impl<Flag: PyBufferRequestType> Drop for PyUntypedBufferView<Flag>
impl<Flag: PyBufferRequestType> Drop for PyUntypedBufferView<Flag>
Auto Trait Implementations§
impl<Flag = PyBufferFlags<false, false, false, false, false, CONTIGUITY_UNDEFINED>> !Send for PyUntypedBufferView<Flag>
impl<Flag = PyBufferFlags<false, false, false, false, false, CONTIGUITY_UNDEFINED>> !Sync for PyUntypedBufferView<Flag>
impl<Flag = PyBufferFlags<false, false, false, false, false, CONTIGUITY_UNDEFINED>> !Unpin for PyUntypedBufferView<Flag>
impl<Flag = PyBufferFlags<false, false, false, false, false, CONTIGUITY_UNDEFINED>> !UnsafeUnpin for PyUntypedBufferView<Flag>
impl<Flag> Freeze for PyUntypedBufferView<Flag>where
PhantomData<Flag>: Freeze,
impl<Flag> RefUnwindSafe for PyUntypedBufferView<Flag>where
PhantomData<Flag>: RefUnwindSafe,
impl<Flag> UnwindSafe for PyUntypedBufferView<Flag>where
PhantomData<Flag>: 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 moreSource§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more