AtomicU16

Struct AtomicU16 

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

An integer type which can be safely shared between threads.

This type has the same in-memory representation as the underlying integer type.

Implementations§

Source§

impl AtomicU16

Source

pub const fn new(v: u16) -> Self

Creates a new atomic integer.

§Examples
use msp430_atomic::AtomicIsize;

let atomic_forty_two  = AtomicIsize::new(42);
Source

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

Returns a mutable reference to the underlying integer.

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

§Examples
use msp430_atomic::AtomicIsize;

let mut some_isize = AtomicIsize::new(10);
assert_eq!(*some_isize.get_mut(), 10);
*some_isize.get_mut() = 5;
assert_eq!(some_isize.load(), 5);
Source

pub fn into_inner(self) -> u16

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::AtomicIsize;

let some_isize = AtomicIsize::new(5);
assert_eq!(some_isize.into_inner(), 5);
Source

pub fn load(&self) -> u16

Loads a value from the atomic integer.

§Examples
use msp430_atomic::AtomicIsize;

let some_isize = AtomicIsize::new(5);

assert_eq!(some_isize.load(), 5);
Source

pub fn store(&self, val: u16)

Stores a value into the atomic integer.

§Examples
use msp430_atomic::AtomicIsize;

let some_isize = AtomicIsize::new(5);

some_isize.store(10);
assert_eq!(some_isize.load(), 10);
Source

pub fn add(&self, val: u16)

Adds to the current value, returning the previous value.

This operation wraps around on overflow.

§Examples
use msp430_atomic::AtomicIsize;

let foo = AtomicIsize::new(0);
foo.add(10);
assert_eq!(foo.load(), 10);
Source

pub fn sub(&self, val: u16)

Subtracts from the current value, returning the previous value.

This operation wraps around on overflow.

§Examples
use msp430_atomic::AtomicIsize;

let foo = AtomicIsize::new(0);
foo.sub(10);
assert_eq!(foo.load(), -10);
Source

pub fn and(&self, val: u16)

Bitwise “and” with the current value.

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

§Examples
use msp430_atomic::AtomicIsize;

let foo = AtomicIsize::new(0b101101);
foo.and(0b110011);
assert_eq!(foo.load(), 0b100001);
Source

pub fn or(&self, val: u16)

Bitwise “or” with the current value.

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

§Examples
use msp430_atomic::AtomicIsize;

let foo = AtomicIsize::new(0b101101);
foo.or(0b110011);
assert_eq!(foo.load(), 0b111111);
Source

pub fn xor(&self, val: u16)

Bitwise “xor” with the current value.

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

§Examples
use msp430_atomic::AtomicIsize;

let foo = AtomicIsize::new(0b101101);
foo.xor(0b110011);
assert_eq!(foo.load(), 0b011110);

Trait Implementations§

Source§

impl Debug for AtomicU16

Source§

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

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

impl Default for AtomicU16

Source§

fn default() -> Self

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

impl Sync for AtomicU16

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.