AtomicBool

Struct AtomicBool 

Source
pub struct AtomicBool { /* private fields */ }
Expand description

A boolean type which can be safely shared between threads.

This type has the same in-memory representation as a bool.

Implementations§

Source§

impl AtomicBool

Source

pub const fn new(v: bool) -> AtomicBool

Creates a new AtomicBool.

§Examples
use msp430_atomic::AtomicBool;

let atomic_true  = AtomicBool::new(true);
let atomic_false = AtomicBool::new(false);
Source

pub fn get_mut(&mut self) -> &mut bool

Returns a mutable reference to the underlying bool.

This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.

§Examples
use msp430_atomic::AtomicBool;

let mut some_bool = AtomicBool::new(true);
assert_eq!(*some_bool.get_mut(), true);
*some_bool.get_mut() = false;
assert_eq!(some_bool.load(), false);
Source

pub fn into_inner(self) -> bool

Consumes the atomic and returns the contained value.

This is safe because passing self by value guarantees that no other threads are concurrently accessing the atomic data.

§Examples
use msp430_atomic::AtomicBool;

let some_bool = AtomicBool::new(true);
assert_eq!(some_bool.into_inner(), true);
Source

pub fn load(&self) -> bool

Loads a value from the bool.

§Examples
use msp430_atomic::AtomicBool;

let some_bool = AtomicBool::new(true);

assert_eq!(some_bool.load(), true);
Source

pub fn store(&self, val: bool)

Stores a value into the bool.

§Examples
use msp430_atomic::AtomicBool;

let some_bool = AtomicBool::new(true);

some_bool.store(false);
assert_eq!(some_bool.load(), false);
Source

pub fn and(&self, val: bool)

Logical “and” with a boolean value.

Performs a logical “and” operation on the current value and the argument val, and sets the new value to the result.

§Examples
use msp430_atomic::AtomicBool;

let foo = AtomicBool::new(true);
foo.and(false);
assert_eq!(foo.load(), false);

let foo = AtomicBool::new(true);
foo.and(true);
assert_eq!(foo.load(), true);

let foo = AtomicBool::new(false);
foo.and(false);
assert_eq!(foo.load(), false);
Source

pub fn nand(&self, val: bool)

Logical “nand” with a boolean value.

Performs a logical “nand” operation on the current value and the argument val, and sets the new value to the result.

§Examples
use msp430_atomic::AtomicBool;

let foo = AtomicBool::new(true);
foo.nand(false);
assert_eq!(foo.load(), true);

let foo = AtomicBool::new(true);
foo.nand(true);
assert_eq!(foo.load() as usize, 0);
assert_eq!(foo.load(), false);

let foo = AtomicBool::new(false);
foo.nand(false);
assert_eq!(foo.load(), true);
Source

pub fn or(&self, val: bool)

Logical “or” with a boolean value.

Performs a logical “or” operation on the current value and the argument val, and sets the new value to the result.

§Examples
use msp430_atomic::AtomicBool;

let foo = AtomicBool::new(true);
foo.or(false);
assert_eq!(foo.load(), true);

let foo = AtomicBool::new(true);
foo.or(true);
assert_eq!(foo.load(), true);

let foo = AtomicBool::new(false);
foo.or(false);
assert_eq!(foo.load(), false);
Source

pub fn xor(&self, val: bool)

Logical “xor” with a boolean value.

Performs a logical “xor” operation on the current value and the argument val, and sets the new value to the result.

§Examples
use msp430_atomic::AtomicBool;

let foo = AtomicBool::new(true);
foo.xor(false);
assert_eq!(foo.load(), true);

let foo = AtomicBool::new(true);
foo.xor(true);
assert_eq!(foo.load(), false);

let foo = AtomicBool::new(false);
foo.xor(false);
assert_eq!(foo.load(), false);

Trait Implementations§

Source§

impl Debug for AtomicBool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AtomicBool

Source§

fn default() -> Self

Creates an AtomicBool initialized to false.

Source§

impl Sync for AtomicBool

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