FracGhostResource

Struct FracGhostResource 

Source
pub struct FracGhostResource<T, const TOTAL: u64> { /* private fields */ }
Expand description

A struct that stores and dispatches FracGhost<T>. Unlike FracGhost, it provides an empty state. It also remembers the value even it is empty.

Implementations§

Source§

impl<T, const TOTAL: u64> FracGhostResource<T, TOTAL>

Source

pub open spec fn wf(self) -> bool

{
    &&& TOTAL > 0
    &&& 0 <= self.frac() <= TOTAL

}

Type invariant.

Source

pub open spec fn is_empty(self) -> bool

{ self.frac() == 0 }

Whether this FracGhostResource is empty, i.e., has no fraction.

Source

pub open spec fn not_empty(self) -> bool

{ !self.is_empty() }

Whether the fraction stored in this FracGhostResource is less than TOTAL.

Source

pub open spec fn is_full(self) -> bool

{ self.frac() == TOTAL }

Whether this FracGhostResource has the full fraction, i.e., TOTAL.

Source

pub closed spec fn storage(self) -> FracGhost<T, TOTAL>

Returns the FracGhost<T,TOTAL> stored in this FracGhostResource.

Source

pub closed spec fn view(self) -> T

Returns the value of type T stored in this FracGhostResource.

Source

pub closed spec fn frac(self) -> int

The fractions stored in this FracGhostResource.

Source

pub closed spec fn id(self) -> Loc

Returns the unique identifier.

Source

pub proof fn arbitrary() -> tracked res : Self

requires
TOTAL > 0,

Create an arbitrary FracGhostResource. Useful as a placeholder.

Source

pub proof fn alloc(value: T) -> tracked res : Self

requires
TOTAL > 0,
ensures
res.not_empty(),
res.is_full(),
res@ == value,
res.wf(),

Allocates a new FracGhostResource with the full fraction and the given value.

Source

pub proof fn split_one(tracked &mut self) -> tracked res : FracGhost<T, TOTAL>

requires
old(self).not_empty(),
ensures
self.id() == old(self).id(),
self.frac() + 1 == old(self).frac(),
self@ == old(self)@,
res.frac() == 1,
res.id() == self.id(),
res@ == self@,
old(self).frac() == 1 ==> self.is_empty(),
self.wf(),

Splits a FracGhost with fraction 1.

Source

pub proof fn split(tracked &mut self, n: int) -> tracked res : FracGhost<T, TOTAL>

requires
1 <= n <= old(self).frac(),
ensures
self.id() == old(self).id(),
self.frac() + n == old(self).frac(),
self@ == old(self)@,
res.frac() == n,
res.id() == self.id(),
res@ == self@,
old(self).frac() == n ==> self.is_empty(),
self.wf(),

Splits a FracGhost with the given fraction.

Source

pub proof fn combine(tracked &mut self, tracked other: FracGhost<T, TOTAL>)

requires
old(self).id() == other.id(),
other@ == old(self)@,
ensures
old(self).frac() + other.frac() > TOTAL ==> false,
old(self).frac() + other.frac() <= TOTAL
    ==> {
        &&& self.id() == old(self).id()
        &&& self@ == old(self)@
        &&& self.frac() == old(self).frac() + other.frac()
        &&& self.wf()

    },

Combines a FracGhost.

Source

pub proof fn validate(tracked &self)

ensures
self.wf(),

FracGhostResource satisfies the type invariant.

Source

pub proof fn validate_full(tracked &self)

requires
self.is_full(),
ensures
self.not_empty(),
self.frac() == TOTAL,
self.wf(),
Source

pub proof fn update(tracked &mut self, value: T)

requires
old(self).is_full(),
ensures
self.is_full(),
self@ == value,
self.id() == old(self).id(),
self.wf(),

Updates the value stored in this FracGhostResource. The fraction must be full before the update.

Auto Trait Implementations§

§

impl<T, const TOTAL: u64> Freeze for FracGhostResource<T, TOTAL>
where T: Freeze,

§

impl<T, const TOTAL: u64> RefUnwindSafe for FracGhostResource<T, TOTAL>
where T: RefUnwindSafe,

§

impl<T, const TOTAL: u64> Send for FracGhostResource<T, TOTAL>
where T: Send,

§

impl<T, const TOTAL: u64> Sync for FracGhostResource<T, TOTAL>
where T: Sync,

§

impl<T, const TOTAL: u64> Unpin for FracGhostResource<T, TOTAL>
where T: Unpin,

§

impl<T, const TOTAL: u64> UnwindSafe for FracGhostResource<T, TOTAL>
where T: UnwindSafe,

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.

§

impl<T, VERUS_SPEC__A> FromSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: From<T>,

§

fn obeys_from_spec() -> bool

§

fn from_spec(v: T) -> VERUS_SPEC__A

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.

§

impl<T, VERUS_SPEC__A> IntoSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: Into<T>,

§

fn obeys_into_spec() -> bool

§

fn into_spec(self) -> T

§

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

§

fn obeys_into_spec() -> bool

§

fn into_spec(self) -> U

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.
§

impl<T, VERUS_SPEC__A> TryFromSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: TryFrom<T>,

§

fn obeys_try_from_spec() -> bool

§

fn try_from_spec( v: T, ) -> Result<VERUS_SPEC__A, <VERUS_SPEC__A as TryFrom<T>>::Error>

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.
§

impl<T, VERUS_SPEC__A> TryIntoSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: TryInto<T>,

§

fn obeys_try_into_spec() -> bool

§

fn try_into_spec(self) -> Result<T, <VERUS_SPEC__A as TryInto<T>>::Error>

§

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

§

fn obeys_try_into_spec() -> bool

§

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