Skip to main content

Lifetime

Struct Lifetime 

Source
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

Source

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.

Source

pub fn state(&self) -> &LifetimeState

Returns the shared state, refreshing the tag first.

Source

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.

Source

pub fn tag(&self) -> usize

Returns the current tag.

Source

pub fn borrow(&self) -> Option<LifetimeRef>

Takes a shared borrow, or returns None when a mutable borrow is out.

Source

pub async fn borrow_async(&self) -> LifetimeRef

Lifetime::borrow, awaiting until it succeeds.

Source

pub fn borrow_mut(&self) -> Option<LifetimeRefMut>

Takes a mutable borrow, or returns None when any other borrow is out.

Source

pub async fn borrow_mut_async(&self) -> LifetimeRefMut

Lifetime::borrow_mut, awaiting until it succeeds.

Source

pub fn lazy(&self) -> LifetimeLazy

Takes a handle that claims no borrow and is checked only when used.

Source

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.

Source

pub async fn read_async<'a, T: ?Sized>( &'a self, data: &'a T, ) -> ValueReadAccess<'a, T>

Lifetime::read, awaiting until it succeeds.

Source

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.

Source

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.

Source

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.

Source

pub async fn write_async<'a, T: ?Sized>( &'a self, data: &'a mut T, ) -> ValueWriteAccess<'a, T>

Lifetime::write, awaiting until it succeeds.

Source

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.

Source

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.

Source

pub fn try_read_lock(&self) -> Option<ReadLock>

Claims read access without holding any data, or returns None when a write guard is live.

Source

pub fn read_lock(&self) -> ReadLock

Lifetime::try_read_lock, spinning until it succeeds.

Source

pub async fn read_lock_async(&self) -> ReadLock

Lifetime::try_read_lock, awaiting until it succeeds.

Source

pub fn try_write_lock(&self) -> Option<WriteLock>

Claims write access without holding any data, or returns None when any access guard is live.

Source

pub fn write_lock(&self) -> WriteLock

Lifetime::try_write_lock, spinning until it succeeds.

Source

pub async fn write_lock_async(&self) -> WriteLock

Lifetime::try_write_lock, awaiting until it succeeds.

Source

pub async fn wait_for_read_access(&self)

Awaits until reading would be allowed, without claiming anything.

Source

pub async fn wait_for_write_access(&self)

Awaits until writing would be allowed, without claiming anything.

Trait Implementations§

Source§

impl Default for Lifetime

Source§

fn default() -> Lifetime

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Finalize for T

Source§

unsafe fn finalize_raw(data: *mut ())

Drops the value stored at data in place. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Initialize for T
where T: Default,

Source§

fn initialize() -> T

Returns the initial value of this type.
Source§

unsafe fn initialize_raw(data: *mut ())

Writes the initial value into already allocated memory. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.