pub struct AtomicOption<T>(/* private fields */);
Expand description
Atomized Option type.
Implementations§
Source§impl<T> AtomicOption<T>
impl<T> AtomicOption<T>
pub fn new(value: Option<T>) -> Self
Sourcepub fn get(&self) -> Option<&'static T>
pub fn get(&self) -> Option<&'static T>
§Example
use sync::atomic::AtomicOption;
let opt = AtomicOption::<u8>::new(None);
assert_eq!(opt.get().is_none(), true);
assert!(opt.is_none());
assert!(!opt.is_some());
let b = opt.swap(Some(1));
assert_eq!(b, None);
assert_eq!(opt.get().is_none(), false);
assert!(!opt.is_none());
assert!(opt.is_some());
Sourcepub fn swap(&self, value: Option<T>) -> Option<T>
pub fn swap(&self, value: Option<T>) -> Option<T>
§Example
use sync::atomic::AtomicOption;
let opt = AtomicOption::<u8>::new(None);
assert_eq!(opt.get().is_none(), true);
assert!(opt.is_none());
assert!(!opt.is_some());
let b = opt.swap(Some(1));
assert_eq!(b, None);
assert_eq!(opt.get().is_none(), false);
assert!(!opt.is_none());
assert!(opt.is_some());
Sourcepub fn is_none(&self) -> bool
pub fn is_none(&self) -> bool
§Example
use sync::atomic::AtomicOption;
let opt = AtomicOption::<u8>::new(None);
assert_eq!(opt.get().is_none(), true);
assert!(opt.is_none());
assert!(!opt.is_some());
let b = opt.swap(Some(1));
assert_eq!(b, None);
assert_eq!(opt.get().is_none(), false);
assert!(!opt.is_none());
assert!(opt.is_some());
Sourcepub fn is_some(&self) -> bool
pub fn is_some(&self) -> bool
§Example
use sync::atomic::AtomicOption;
let opt = AtomicOption::<u8>::new(None);
assert_eq!(opt.get().is_none(), true);
assert!(opt.is_none());
assert!(!opt.is_some());
let b = opt.swap(Some(1));
assert_eq!(b, None);
assert_eq!(opt.get().is_none(), false);
assert!(!opt.is_none());
assert!(opt.is_some());
Trait Implementations§
Source§impl<T> Default for AtomicOption<T>
impl<T> Default for AtomicOption<T>
Auto Trait Implementations§
impl<T> !Freeze for AtomicOption<T>
impl<T> RefUnwindSafe for AtomicOption<T>
impl<T> Send for AtomicOption<T>
impl<T> Sync for AtomicOption<T>
impl<T> Unpin for AtomicOption<T>
impl<T> UnwindSafe for AtomicOption<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more