Skip to main content

atomic_buf

Struct atomic_buf 

Source
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

Source

pub fn new<T>(data: &T) -> &Self
where T: AsRef<[MaxAtomic]> + ?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 as_buf_mut(&mut self) -> &mut buf

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>) -> 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.

Source

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.

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 atomic_buf

Source

pub const ALIGNMENT: usize = MAX_ALIGN

Source

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

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for &atomic_buf

Source§

fn default() -> Self

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

impl Eq for atomic_buf

Source§

impl PartialEq for atomic_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 atomic_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.

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