Type Alias arc_swap::ArcSwapOption

source ·
pub type ArcSwapOption<T> = ArcSwapAny<Option<Arc<T>>>;
Expand description

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_full().is_none());
assert!(shared.swap(Some(Arc::new(42))).is_none());
assert_eq!(42, **shared.load_full().as_ref().unwrap());

Aliased Type§

struct ArcSwapOption<T> { /* private fields */ }

Implementations§

source§

impl<T> ArcSwapOption<T>

source

pub const fn const_empty() -> Self

A const-fn equivalent of empty.

Just like empty, this creates an None-holding ArcSwapOption. The empty is, however, more general ‒ this is available only for the default strategy, while empty is for any Default-constructible strategy (current or future one).

§Examples
static GLOBAL_DATA: ArcSwapOption<usize> = ArcSwapOption::const_empty();

assert!(GLOBAL_DATA.load().is_none());
GLOBAL_DATA.store(Some(Arc::new(42)));
assert_eq!(42, **GLOBAL_DATA.load().as_ref().unwrap());