Struct arc_swap::Guard [−][src]
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]
impl<'a, T: RefCnt> Guard<'a, T>
pub fn upgrade(guard: &Self) -> T
[src]
pub fn upgrade(guard: &Self) -> T
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)); } }
pub fn lease(guard: &Self) -> Lease<T>
[src]
pub fn lease(guard: &Self) -> Lease<T>
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.
pub fn get_ref<'g>(guard: &'g Self) -> Option<&'g T::Base>
[src]
pub fn get_ref<'g>(guard: &'g Self) -> Option<&'g T::Base>
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]
impl<'a, T: RefCnt> AsRaw<T::Base> for Guard<'a, T>
impl<'a, T: NonNull> Deref for Guard<'a, T>
[src]
impl<'a, T: NonNull> Deref for Guard<'a, T>
type Target = T::Base
The resulting type after dereferencing.
fn deref(&self) -> &T::Base
[src]
fn deref(&self) -> &T::Base
Dereferences the value.
impl<'a, T: RefCnt> Drop for Guard<'a, T>
[src]
impl<'a, T: RefCnt> Drop for Guard<'a, T>