Struct arc_swap::Guard[][src]

pub struct Guard<'a, T: RefCnt + 'a> where
    T::Base: 'a, 
{ /* fields omitted */ }

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.

Methods

impl<'a, T: RefCnt> Guard<'a, T>
[src]

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));
    }
}

Upgrades the guard to a Lease.

This is useful for cases when the value needs to be held for intermediate time spans, like when manipulating a data structure.

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

impl<'a, T: RefCnt> AsRaw<T::Base> for Guard<'a, T>
[src]

Converts the value into a raw pointer. Read more

impl<'a, T: NonNull> Deref for Guard<'a, T>
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<'a, T: RefCnt> Drop for Guard<'a, T>
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl<'a, T> !Send for Guard<'a, T>

impl<'a, T> !Sync for Guard<'a, T>