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
impl cell_buf
Sourcepub fn new<T>(data: &T) -> &Self
pub fn new<T>(data: &T) -> &Self
Wraps an aligned buffer into buf.
This method will never panic, as the alignment of the data is guaranteed.
Sourcepub fn split_at(&self, at: usize) -> (&Self, &Self)
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.
Sourcepub fn as_texels<P>(&self, texel: Texel<P>) -> &Cell<[P]>
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.
Sourcepub fn map_within<P, Q>(
&self,
src: impl RangeBounds<usize>,
dest: usize,
f: impl Fn(P) -> Q,
p: Texel<P>,
q: Texel<Q>,
)
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
impl cell_buf
pub const ALIGNMENT: usize = MAX_ALIGN
pub fn from_slice(values: &[MaxCell]) -> &Self
Sourcepub fn from_bytes(bytes: &[Cell<u8>]) -> Option<&Self>
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.
Sourcepub fn from_bytes_mut(bytes: &mut [u8]) -> Option<&Self>
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.