Skip to main content

LifetimeToken

Struct LifetimeToken 

Source
pub struct LifetimeToken(/* private fields */);
Expand description

A token signaling that the corresponding lifetime is still active.

This token is not duplicable, but it may be split into multiple other tokens. Each token has an associated fraction; if it is 1, the lifetime may be killed to end borrows made at this lifetime.

This type is purely ghost, and all operations on its values compile to no-ops.

Implementations§

Source§

impl LifetimeToken

Source

pub fn frac(self) -> PositiveReal

The fraction owned by this particular token.

If the token owns the full fraction (1), it can be used to end the lifetime.

logic

Source

pub fn lft(self) -> Lifetime

The lifetime identifier associated with this particular token.

Only tokens with the same lifetime can be combined.

logic

Source

pub fn new() -> Self

Get a full lifetime token for a fresh lifetime.

terminates

ghost

ensures

result.frac() == PositiveReal::from_int(1)

Source

pub fn split(self) -> (Self, Self)

Split a lifetime token into two tokens, by dividing its fraction by 2.

terminates

ghost

ensures

result.0.lft() == self.lft() && result.1.lft() == self.lft()

ensures

result.0.frac() + result.1.frac() == self.frac()

ensures

result.0.frac() == self.frac() / PositiveReal::from_int(2)
       && result.1.frac() == self.frac() / PositiveReal::from_int(2)
Source

pub fn split_off(&mut self) -> Self

Split a lifetime token from this token, by removing half of the token’s fraction and giving it to the result.

terminates

ghost

ensures

result.lft() == self.lft() && (^self).lft() == (*self).lft()

ensures

result.frac() + (^self).frac() == self.frac()

ensures

result.frac() == self.frac() / PositiveReal::from_int(2) && (^self).frac() == self.frac() / PositiveReal::from_int(2)
Source

pub fn join(self, other: Self) -> Self

Combine two lifetime tokens together, adding their fractions.

terminates

ghost

requires

self.lft() == other.lft()

ensures

result.lft() == self.lft()

ensures

result.frac() == self.frac() + other.frac()

Source

pub fn join_in(&mut self, other: Self)

Same as Self::join, but with a mutable borrow.

terminates

ghost

requires

self.lft() == other.lft()

ensures

(^self).lft() == self.lft()

ensures

(^self).frac() == self.frac() + other.frac()

Source

pub fn end(self) -> LifetimeDead

Terminates the lifetime, giving back a ‘dead’ token.

terminates

ghost

requires

self.frac() == PositiveReal::from_int(1)

ensures

result.lft() == self.lft()

Trait Implementations§

Source§

impl Default for LifetimeToken

Source§

fn default() -> Self

terminates

ghost

ensures

result.frac() == PositiveReal::from_int(1)

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.