Struct arc_swap::access::AccessConvert
source · [−]pub struct AccessConvert<D>(pub D);
Expand description
A workaround to allow double-dyn mapping, since Box<dyn DynAccess>
doesn’t implement Access
and Map needs that.
use std::sync::Arc;
use arc_swap::ArcSwap;
use arc_swap::access::{AccessConvert, DynAccess, Map};
struct Inner {
val: usize,
}
struct Middle {
inner: Inner,
}
struct Outer {
middle: Middle,
}
let outer = Arc::new(ArcSwap::from_pointee(Outer {
middle: Middle {
inner: Inner {
val: 42,
}
}
}));
let middle: Arc<dyn DynAccess<Middle>> =
Arc::new(Map::new(outer, |outer: &Outer| &outer.middle));
let inner: Arc<dyn DynAccess<Inner>> =
Arc::new(Map::new(AccessConvert(middle), |middle: &Middle| &middle.inner));
let guard = inner.load();
assert_eq!(42, guard.val);
Tuple Fields
0: D
Trait Implementations
Auto Trait Implementations
impl<D> RefUnwindSafe for AccessConvert<D> where
D: RefUnwindSafe,
impl<D> Send for AccessConvert<D> where
D: Send,
impl<D> Sync for AccessConvert<D> where
D: Sync,
impl<D> Unpin for AccessConvert<D> where
D: Unpin,
impl<D> UnwindSafe for AccessConvert<D> where
D: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, A> DynAccess<T> for A where
A: Access<T>,
<A as Access<T>>::Guard: 'static,
impl<T, A> DynAccess<T> for A where
A: Access<T>,
<A as Access<T>>::Guard: 'static,
sourcefn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of Access::load
.