pub struct AccessConvert<D>(pub D);
Expand description
In previous versions, Box<dyn DynAccess>
didn’t implement Access, to use inside Map one
could use this wrapper. Since then, a way was found to solve it. In most cases, this wrapper is
no longer necessary.
This is left in place for two reasons:
- Backwards compatibility.
- Corner-cases not covered by the found solution. For example, trait inheritance in the form of
Box<dyn SomeTrait>
whereSomeTrait: Access
doesn’t work out of the box and still needs this wrapper.
§Examples
The example is for the simple case (which is no longer needed, but may help as an inspiration).
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> Freeze for AccessConvert<D>where
D: Freeze,
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§
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
source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load
.