Struct AtomicBitBox

Source
pub struct AtomicBitBox<T: HasAtomicInt = u8, A: Allocator = Global> { /* private fields */ }
Available on crate feature alloc only.
Expand description

An atomic bitfield with a static size, stored in a boxed slice.

This struct provides methods for working with atomic bitfields, allowing concurrent access and manipulation of individual bits. It is particularly useful when you need to store a large number of boolean flags and want to minimize memory usage.

§Example

use utils_atomics::{AtomicBitBox};
use core::sync::atomic::Ordering;

let bit_box = AtomicBitBox::<u8>::new(10);
assert_eq!(bit_box.get(3, Ordering::Relaxed), Some(false));
bit_box.set(3, Ordering::Relaxed);
assert_eq!(bit_box.get(3, Ordering::Relaxed), Some(true));

Implementations§

Source§

impl<T> AtomicBitBox<T>

Source

pub fn new(len: usize) -> Self

Allocates a new bitfield. All values are initialized to false.

§Panics

This method panics if the memory allocation fails

Source

pub fn try_new(len: usize) -> Result<Self, AllocError>

Allocates a new bitfield. All values are initialized to false.

§Errors

This method returns an error if the memory allocation fails

Source§

impl<T, A: Allocator> AtomicBitBox<T, A>

Source

pub fn new_in(len: usize, alloc: A) -> Self

Allocates a new bitfield. All values are initialized to false.

§Panics

This method panics if the memory allocation fails

Source

pub fn try_new_in(len: usize, alloc: A) -> Result<Self, AllocError>

Allocates a new bitfield. All values are initialized to false.

§Errors

This method returns an error if the memory allocation fails

Source

pub fn get(&self, idx: usize, order: Ordering) -> Option<bool>

Returns the value of the bit at the specified index, or None if the index is out of bounds.

order defines the memory ordering for this operation.

Source

pub fn set_value(&self, v: bool, idx: usize, order: Ordering) -> Option<bool>

Sets the value of the bit at the specified index and returns the previous value, or None if the index is out of bounds.

order defines the memory ordering for this operation.

Source

pub fn set(&self, idx: usize, order: Ordering) -> Option<bool>

Sets the bit at the specified index to true and returns the previous value, or None if the index is out of bounds.

order defines the memory ordering for this operation.

Source

pub fn clear(&self, idx: usize, order: Ordering) -> Option<bool>

Sets the bit at the specified index to false and returns the previous value, or None if the index is out of bounds.

order defines the memory ordering for this operation.

Auto Trait Implementations§

§

impl<T, A> Freeze for AtomicBitBox<T, A>
where A: Freeze,

§

impl<T, A> RefUnwindSafe for AtomicBitBox<T, A>

§

impl<T, A> Send for AtomicBitBox<T, A>
where A: Send,

§

impl<T, A> Sync for AtomicBitBox<T, A>
where A: Sync,

§

impl<T, A> Unpin for AtomicBitBox<T, A>

§

impl<T, A> UnwindSafe for AtomicBitBox<T, A>

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.