Struct arc_swap::Guard

source ·
pub struct Guard<'a, T: RefCnt + 'a, S: LockStorage + 'a = Global>where
    T::Base: 'a,
{ /* private fields */ }
Expand description

A short-term proxy object from peek.

This allows for upgrading to a full smart pointer and borrowing of the value inside. It also dereferences to the actual pointed to type if the smart pointer guarantees not to contain NULL values (eg. on Arc, but not on Option<Arc>).

Warning

Do not store or keep around for a long time, as this prevents all the writer methods from completing on all the swap objects in the whole program from completing.

Implementations

Upgrades the guard to a real Arc.

This shares the reference count with all the Arc inside the corresponding ArcSwap. Use this if you need to hold the object for longer periods of time.

See peek for details.

Note that this is associated function (so it doesn’t collide with the thing pointed to):

Examples
let a = ArcSwap::from(Arc::new(42));
let mut ptr = None;
{ // limit the scope where the guard lives
    let guard = a.peek();
    if *guard > 40 {
        ptr = Some(Guard::upgrade(&guard));
    }
}
👎Deprecated: Use upgrade instead

Upgrades the guard to a Lease.

This is preserved here for backwards compatibility. Use upgrade instead (it has the same cost).

Gets a reference to the value inside.

This is returned as Option even for pointers that can’t return Null, to have a common interface. The non-null ones also implement the Deref trait, so they can more easily be used as that.

Trait Implementations

Converts the value into a raw pointer. Read more
The resulting type after dereferencing.
Dereferences the value.
Executes the destructor for this type. 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

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.