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

DynAccess to Access wrapper.

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

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.