Skip to main content

PyBufferView

Struct PyBufferView 

Source
#[repr(transparent)]
pub struct PyBufferView<T, Flag: PyBufferRequestType = PyBufferFlags<true, true, true, true, false, CONTIGUITY_UNDEFINED>>(PyUntypedBufferView<Flag>, PhantomData<[T]>);
Available on Py_3_11 or non-Py_LIMITED_API only.
Expand description

A typed form of PyUntypedBufferView. Not constructible directly — use PyBufferView::with() or PyBufferView::with_flags().

Tuple Fields§

§0: PyUntypedBufferView<Flag>§1: PhantomData<[T]>

Implementations§

Source§

impl<T: Element> PyBufferView<T>

Source

pub fn with<R>( obj: &Bound<'_, PyAny>, f: impl FnOnce(&PyBufferView<T>) -> R, ) -> PyResult<R>

Acquire a typed buffer view with PyBufferRequest::full_ro() flags, validating that the buffer format is compatible with T.

Source

pub fn with_flags<Flag, R>( obj: &Bound<'_, PyAny>, flags: PyBufferRequest<Flag>, f: impl FnOnce(&PyBufferView<T, Flag>) -> R, ) -> PyResult<R>

Acquire a typed buffer view with the given flags.

The flags are passed to the exporter as requested. Format information must be available for type validation: PyBufferRequest::simple() and its writable variant imply unsigned bytes, while other requests must include .format().

Source§

impl<T: Element, Flag: PyBufferRequestType> PyBufferView<T, Flag>

Source

pub fn as_slice_ptr(&self) -> Option<NonNull<[T]>>

Gets the buffer memory as a slice.

Returns None if the buffer is not C-contiguous.

Accessing the memory requires upholding the buffer memory access requirements.

Source

pub fn as_fortran_slice_ptr(&self) -> Option<NonNull<[T]>>

Gets the buffer memory as a slice.

Returns None if the buffer is not Fortran-contiguous.

Accessing the memory requires upholding the buffer memory access requirements.

Source

pub fn as_contiguous_slice_ptr(&self) -> NonNull<[T]>

Gets the buffer memory as a slice. The buffer is guaranteed C-contiguous.

Accessing the memory requires upholding the buffer memory access requirements.

Source

pub fn as_fortran_contiguous_slice_ptr(&self) -> NonNull<[T]>

Gets the buffer memory as a slice pointer. The buffer is guaranteed Fortran-contiguous.

Accessing the memory requires upholding the buffer memory access requirements.

Source

fn slice_pointer_internal(&self) -> NonNull<[T]>

Methods from Deref<Target = PyUntypedBufferView<Flag>>§

Source

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.

Source

pub fn obj<'py>(&self, py: Python<'py>) -> Option<&Bound<'py, PyAny>>

Returns the Python object that owns the buffer data.

Source

pub fn readonly(&self) -> bool

Gets whether the underlying buffer is read-only.

Source

pub fn item_size(&self) -> usize

Gets the size of a single element, in bytes.

Source

pub fn item_count(&self) -> usize

Gets the total number of items.

Source

pub fn len_bytes(&self) -> usize

item_size() * item_count(). For contiguous arrays, this is the length of the underlying memory block.

Source

pub fn dimensions(&self) -> usize

Gets the number of dimensions.

Always at least 1. Scalar buffers are rejected during acquisition.

Source

pub fn is_c_contiguous(&self) -> bool

Gets whether the buffer is contiguous in C-style order.

Source

pub fn is_fortran_contiguous(&self) -> bool

Gets whether the buffer is contiguous in Fortran-style order.

Source

pub fn format(&self) -> &CStr
where Flag: IncludesFormat,

A struct module style string describing the contents of a single item.

Source

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.

Source

fn ensure_compatible_with<T: Element>(&self) -> PyResult<()>
where Flag: IncludesFormat,

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T, Flag: PyBufferRequestType> Debug for PyBufferView<T, Flag>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, Flag: PyBufferRequestType> Deref for PyBufferView<T, Flag>

Source§

type Target = PyUntypedBufferView<Flag>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<T, Flag = PyBufferFlags<true, true, true, true, false, CONTIGUITY_UNDEFINED>> !Send for PyBufferView<T, Flag>

§

impl<T, Flag = PyBufferFlags<true, true, true, true, false, CONTIGUITY_UNDEFINED>> !Sync for PyBufferView<T, Flag>

§

impl<T, Flag = PyBufferFlags<true, true, true, true, false, CONTIGUITY_UNDEFINED>> !Unpin for PyBufferView<T, Flag>

§

impl<T, Flag = PyBufferFlags<true, true, true, true, false, CONTIGUITY_UNDEFINED>> !UnsafeUnpin for PyBufferView<T, Flag>

§

impl<T, Flag> Freeze for PyBufferView<T, Flag>

§

impl<T, Flag> RefUnwindSafe for PyBufferView<T, Flag>

§

impl<T, Flag> UnwindSafe for PyBufferView<T, Flag>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T> SomeWrap<T> for T

Source§

fn wrap(self) -> Option<T>

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here