pub struct AccessConvert<D>(pub D);
Expand description

DynAccess to Access wrapper.

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> where SomeTrait: 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§

source§

impl<T, D> Access<T> for AccessConvert<D>
where D: Deref, D::Target: DynAccess<T>,

§

type Guard = DynGuard<T>

A guard object containing the value and keeping it alive. Read more
source§

fn load(&self) -> Self::Guard

The loading method. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, A> DynAccess<T> for A
where A: Access<T>, <A as Access<T>>::Guard: 'static,

source§

fn load(&self) -> DynGuard<T>

The equivalent of Access::load.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.