Skip to main content

cell_buf

Struct cell_buf 

Source
pub struct cell_buf(/* private fields */);
Expand description

An aligned slice of shared-access memory.

This is a wrapper around a cell of a byte slice that additionally requires the slice to be highly aligned.

See pixel.rs for the only constructors.

Implementations§

Source§

impl cell_buf

Source

pub fn new<T>(data: &T) -> &Self
where T: AsRef<[MaxCell]> + ?Sized,

Wraps an aligned buffer into buf.

This method will never panic, as the alignment of the data is guaranteed.

Source

pub fn len(&self) -> usize

Get the length of available memory in bytes.

Source

pub fn truncate(&self, at: usize) -> &Self

Reduce the number of bytes covered by this slice.

Source

pub fn split_at(&self, at: usize) -> (&Self, &Self)

Split into two aligned buffers.

§Panics

This panics if the byte offset given by at is not aligned according to max alignment or if the index is out-of-bounds.

Source

pub fn as_texels<P>(&self, texel: Texel<P>) -> &Cell<[P]>

Reinterpret the buffer for the specific texel type.

The alignment of P is already checked to be smaller than MAX_ALIGN through the constructor of Texel. The slice will have the maximum length possible but may leave unused bytes in the end.

Source

pub fn map_within<P, Q>( &self, src: impl RangeBounds<usize>, dest: usize, f: impl Fn(P) -> Q, p: Texel<P>, q: Texel<Q>, )

Apply a mapping function to some elements.

The indices src and dest are indices as if the slice were interpreted as [P] or [Q] respectively.

The types may differ which allows the use of this function to prepare a reinterpretation cast of a typed buffer. This function chooses the order of function applications such that values are not overwritten before they are used, i.e. the function arguments are exactly the previously visible values. This is even less trivial than for copy if the parameter types differ in size.

§Panics

This function panics if src or the implied range of dest are out of bounds.

Source§

impl cell_buf

Source

pub const ALIGNMENT: usize = MAX_ALIGN

Source

pub fn from_slice(values: &[MaxCell]) -> &Self

Source

pub fn from_bytes(bytes: &[Cell<u8>]) -> Option<&Self>

Interpret a slice of bytes in an unsynchronized shared cell_buf.

The bytes need to be aligned to ALIGNMENT.

Source

pub fn from_bytes_mut(bytes: &mut [u8]) -> Option<&Self>

Wrap bytes in an unsynchronized shared cell_buf.

The bytes need to be aligned to ALIGNMENT.

Trait Implementations§

Source§

impl Default for &cell_buf

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for cell_buf

Source§

impl<T> Index<TexelRange<T>> for cell_buf

Source§

type Output = [Cell<T>]

The returned type after indexing.
Source§

fn index(&self, index: TexelRange<T>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for cell_buf

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<[u8]> for cell_buf

Source§

fn eq(&self, other: &[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<cell_buf> for [u8]

Source§

fn eq(&self, other: &cell_buf) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

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