pub struct Lifetime(/* private fields */);Expand description
Owner of a runtime borrow state, kept next to the value it describes.
Dropping it, or calling Lifetime::invalidate, kills every handle
taken from it. See the module docs for the borrow and access
model.
Implementations§
Source§impl Lifetime
impl Lifetime
Sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Kills every handle taken so far and starts over with fresh counters.
Call this when the value behind the lifetime is replaced, so that old handles cannot reach the new value.
Sourcepub fn state(&self) -> &LifetimeState
pub fn state(&self) -> &LifetimeState
Returns the shared state, refreshing the tag first.
Sourcepub fn update_tag(&self)
pub fn update_tag(&self)
Re-stamps the tag with the current address of this lifetime.
Needed after the lifetime was moved in memory, so handles taken before the move keep upgrading.
Sourcepub fn borrow(&self) -> Option<LifetimeRef>
pub fn borrow(&self) -> Option<LifetimeRef>
Takes a shared borrow, or returns None when a mutable borrow is out.
Sourcepub async fn borrow_async(&self) -> LifetimeRef
pub async fn borrow_async(&self) -> LifetimeRef
Lifetime::borrow, awaiting until it succeeds.
Sourcepub fn borrow_mut(&self) -> Option<LifetimeRefMut>
pub fn borrow_mut(&self) -> Option<LifetimeRefMut>
Takes a mutable borrow, or returns None when any other borrow is out.
Sourcepub async fn borrow_mut_async(&self) -> LifetimeRefMut
pub async fn borrow_mut_async(&self) -> LifetimeRefMut
Lifetime::borrow_mut, awaiting until it succeeds.
Sourcepub fn lazy(&self) -> LifetimeLazy
pub fn lazy(&self) -> LifetimeLazy
Takes a handle that claims no borrow and is checked only when used.
Sourcepub fn read<'a, T: ?Sized>(
&'a self,
data: &'a T,
) -> Option<ValueReadAccess<'a, T>>
pub fn read<'a, T: ?Sized>( &'a self, data: &'a T, ) -> Option<ValueReadAccess<'a, T>>
Guards data for reading, or returns None while a write guard is
live.
The caller has to pass the data that this lifetime guards. The lifetime only tracks the permission.
Sourcepub async fn read_async<'a, T: ?Sized>(
&'a self,
data: &'a T,
) -> ValueReadAccess<'a, T>
pub async fn read_async<'a, T: ?Sized>( &'a self, data: &'a T, ) -> ValueReadAccess<'a, T>
Lifetime::read, awaiting until it succeeds.
Sourcepub unsafe fn read_ptr<T: ?Sized>(
&self,
data: *const T,
) -> Option<ValueReadAccess<'_, T>>
pub unsafe fn read_ptr<T: ?Sized>( &self, data: *const T, ) -> Option<ValueReadAccess<'_, T>>
Lifetime::read over a raw pointer.
§Safety
data must stay valid and aligned for as long as the returned guard
lives. A null pointer yields None.
Sourcepub async unsafe fn read_ptr_async<'a, T: ?Sized + 'a>(
&'a self,
data: *const T,
) -> ValueReadAccess<'a, T>
pub async unsafe fn read_ptr_async<'a, T: ?Sized + 'a>( &'a self, data: *const T, ) -> ValueReadAccess<'a, T>
Lifetime::read_ptr, awaiting until it succeeds.
§Safety
Same as Lifetime::read_ptr, and data must also stay valid across
every await point.
Sourcepub fn write<'a, T: ?Sized>(
&'a self,
data: &'a mut T,
) -> Option<ValueWriteAccess<'a, T>>
pub fn write<'a, T: ?Sized>( &'a self, data: &'a mut T, ) -> Option<ValueWriteAccess<'a, T>>
Guards data for writing, or returns None while any other access
guard is live.
Sourcepub async fn write_async<'a, T: ?Sized>(
&'a self,
data: &'a mut T,
) -> ValueWriteAccess<'a, T>
pub async fn write_async<'a, T: ?Sized>( &'a self, data: &'a mut T, ) -> ValueWriteAccess<'a, T>
Lifetime::write, awaiting until it succeeds.
Sourcepub unsafe fn write_ptr<T: ?Sized>(
&self,
data: *mut T,
) -> Option<ValueWriteAccess<'_, T>>
pub unsafe fn write_ptr<T: ?Sized>( &self, data: *mut T, ) -> Option<ValueWriteAccess<'_, T>>
Lifetime::write over a raw pointer.
§Safety
data must stay valid, aligned and unaliased for as long as the
returned guard lives. A null pointer yields None.
Sourcepub async unsafe fn write_ptr_async<'a, T: ?Sized + 'a>(
&'a self,
data: *mut T,
) -> ValueWriteAccess<'a, T>
pub async unsafe fn write_ptr_async<'a, T: ?Sized + 'a>( &'a self, data: *mut T, ) -> ValueWriteAccess<'a, T>
Lifetime::write_ptr, awaiting until it succeeds.
§Safety
Same as Lifetime::write_ptr, and data must also stay valid across
every await point.
Sourcepub fn try_read_lock(&self) -> Option<ReadLock>
pub fn try_read_lock(&self) -> Option<ReadLock>
Claims read access without holding any data, or returns None when a
write guard is live.
Sourcepub fn read_lock(&self) -> ReadLock
pub fn read_lock(&self) -> ReadLock
Lifetime::try_read_lock, spinning until it succeeds.
Sourcepub async fn read_lock_async(&self) -> ReadLock
pub async fn read_lock_async(&self) -> ReadLock
Lifetime::try_read_lock, awaiting until it succeeds.
Sourcepub fn try_write_lock(&self) -> Option<WriteLock>
pub fn try_write_lock(&self) -> Option<WriteLock>
Claims write access without holding any data, or returns None when
any access guard is live.
Sourcepub fn write_lock(&self) -> WriteLock
pub fn write_lock(&self) -> WriteLock
Lifetime::try_write_lock, spinning until it succeeds.
Sourcepub async fn write_lock_async(&self) -> WriteLock
pub async fn write_lock_async(&self) -> WriteLock
Lifetime::try_write_lock, awaiting until it succeeds.
Sourcepub async fn wait_for_read_access(&self)
pub async fn wait_for_read_access(&self)
Awaits until reading would be allowed, without claiming anything.
Sourcepub async fn wait_for_write_access(&self)
pub async fn wait_for_write_access(&self)
Awaits until writing would be allowed, without claiming anything.