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§

A guard object containing the value and keeping it alive. Read more
The loading method. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
The equivalent of Access::load.

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.