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
sourceimpl<'a, T: RefCnt, S: LockStorage> Guard<'a, T, S>
impl<'a, T: RefCnt, S: LockStorage> Guard<'a, T, S>
sourcepub fn upgrade(guard: &Self) -> T
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));
}
}
Trait Implementations
sourceimpl<'a, T: NonNull, S: LockStorage> Deref for Guard<'a, T, S>
impl<'a, T: NonNull, S: LockStorage> Deref for Guard<'a, T, S>
sourceimpl<'a, T: RefCnt, S: LockStorage> Drop for Guard<'a, T, S>
impl<'a, T: RefCnt, S: LockStorage> Drop for Guard<'a, T, S>
impl<'a, T, S> Send for Guard<'a, T, S> where
T: RefCnt + Send + Sync,
S: LockStorage,
T::Base: Send + Sync,
impl<'a, T, S> Sync for Guard<'a, T, S> where
T: RefCnt + Send + Sync,
S: LockStorage,
T::Base: Send + Sync,
Auto Trait Implementations
impl<'a, T, S> RefUnwindSafe for Guard<'a, T, S> where
S: RefUnwindSafe,
<T as RefCnt>::Base: RefUnwindSafe,
impl<'a, T, S> Unpin for Guard<'a, T, S>
impl<'a, T, S> UnwindSafe for Guard<'a, T, S> where
S: RefUnwindSafe,
<T as RefCnt>::Base: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more