Expand description
This crate provides two thread-safe, non-blocking, no-std synchronization primitives: ExclusiveCell
and CallOnce
.
ExclusiveCell
can be accessed at most once and provides mutable access to the stored contents:
use exclusive_cell::ExclusiveCell;
static EXCLUSIVE_CELL: ExclusiveCell<usize> = ExclusiveCell::new(5);
let number = EXCLUSIVE_CELL.take().unwrap();
assert_eq!(number, &mut 5);
assert!(EXCLUSIVE_CELL.take().is_none());
CallOnce
can only be called once sucessfully:
use exclusive_cell::CallOnce;
static CALL_ONCE: CallOnce = CallOnce::new();
assert!(CALL_ONCE.call_once().is_ok());
assert!(CALL_ONCE.call_once().is_err());
Structsยง
- Call
Once - A synchronization primitive that can only be called once sucessfully.
- Call
Once Error - The
CallOnceError
error indicates thatCallOnce::call_once
has been called more than once. - Exclusive
Cell - A synchronization primitive which can be accessed only once.