Type Definition arc_swap::ArcSwapOption [−][src]
type ArcSwapOption<T> = ArcSwapAny<Option<Arc<T>>>;
An atomic storage for Option<Arc>
.
This is very similar to ArcSwap
, but allows storing NULL values, which
is useful in some situations.
This is a type alias only. Most of the methods are described on
ArcSwapAny
. Even though the examples there often use ArcSwap
,
they are applicable to ArcSwapOption
with appropriate changes.
Examples
use std::sync::Arc; use arc_swap::ArcSwapOption; let shared = ArcSwapOption::from(None); assert!(shared.load().is_none()); assert!(shared.swap(Some(Arc::new(42))).is_none()); assert_eq!(42, *shared.load().unwrap());
Methods
impl<T> ArcSwapOption<T>
[src]
impl<T> ArcSwapOption<T>
pub fn from_pointee<V: Into<Option<T>>>(val: V) -> Self
[src]
pub fn from_pointee<V: Into<Option<T>>>(val: V) -> Self
A convenience constructor directly from a pointed-to value.
This just allocates the Arc
under the hood.
Examples
use arc_swap::ArcSwapOption; let empty: ArcSwapOption<usize> = ArcSwapOption::from_pointee(None); assert!(empty.load().is_none()); let non_empty: ArcSwapOption<usize> = ArcSwapOption::from_pointee(42); assert_eq!(42, *non_empty.load().unwrap());
pub fn empty() -> Self
[src]
pub fn empty() -> Self
A convenience constructor for an empty value.
This is equivalent to ArcSwapOption::new(none)
.