pub struct atomic_buf(/* private fields */);Expand description
An aligned slice of atomic memory.
In contrast to other types, this can not be slice at arbitrary byte ends since we must
still utilize potentially full atomic instructions for the underlying interaction! Until we get
custom metadata, we have our own ‘reference type’ here with AtomicSliceRef. The slice
reference always extends over a slice of the underlying MaxAtomic type and only stores
offsets into this.
This type is relatively useless in the public interface, this makes interfaces slightly less convenient but it is internal to the library anyways.
Note: Contrary to buf, this type can not be sliced at arbitrary locations. Use the
conversion to atomic_ref for this.
Implementations§
Source§impl atomic_buf
impl atomic_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.
pub fn as_buf_mut(&mut self) -> &mut buf
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>) -> AtomicSliceRef<'_, P>
pub fn as_texels<P>(&self, texel: Texel<P>) -> AtomicSliceRef<'_, 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 index<T>(&self, index: TexelRange<T>) -> AtomicSliceRef<'_, T>
pub fn index<T>(&self, index: TexelRange<T>) -> AtomicSliceRef<'_, T>
Index into this buffer at a generalized, potentially skewed, typed index.
§Panics
This method panics if the index is out-of-range.
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 atomic_buf
impl atomic_buf
pub const ALIGNMENT: usize = MAX_ALIGN
pub fn from_slice(values: &[MaxAtomic]) -> &Self
Sourcepub fn from_bytes(bytes: AtomicSliceRef<'_, u8>) -> Option<&Self>
pub fn from_bytes(bytes: AtomicSliceRef<'_, u8>) -> Option<&Self>
Wrap a sub-slice of bytes from an atomic buffer into a new atomic_buf.
The bytes need to be aligned to ALIGNMENT. Returns None if these checks fail and return
the newly wrapped buffer in Some otherwise.
Sourcepub fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self>
pub fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self>
Wrap bytes in an atomic buf.
The bytes need to be aligned to ALIGNMENT. Additionally the length must be a multiple of
the MaxAtomic size’s units. Returns None if these checks fail and return the newly
wrapped buffer in Some otherwise.