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>
impl<T, const TOTAL: u64> FracGhostResource<T, TOTAL>
Sourcepub open spec fn wf(self) -> bool
pub open spec fn wf(self) -> bool
{
&&& TOTAL > 0
&&& 0 <= self.frac() <= TOTAL
}Type invariant.
Sourcepub open spec fn is_empty(self) -> bool
pub open spec fn is_empty(self) -> bool
{ self.frac() == 0 }Whether this FracGhostResource is empty, i.e., has no fraction.
Sourcepub open spec fn not_empty(self) -> bool
pub open spec fn not_empty(self) -> bool
{ !self.is_empty() }Whether the fraction stored in this FracGhostResource is less than TOTAL.
Sourcepub open spec fn is_full(self) -> bool
pub open spec fn is_full(self) -> bool
{ self.frac() == TOTAL }Whether this FracGhostResource has the full fraction, i.e., TOTAL.
Sourcepub closed spec fn storage(self) -> FracGhost<T, TOTAL>
pub closed spec fn storage(self) -> FracGhost<T, TOTAL>
Returns the FracGhost<T,TOTAL> stored in this FracGhostResource.
Sourcepub closed spec fn view(self) -> T
pub closed spec fn view(self) -> T
Returns the value of type T stored in this FracGhostResource.
Sourcepub proof fn arbitrary() -> tracked res : Self
pub proof fn arbitrary() -> tracked res : Self
TOTAL > 0,Create an arbitrary FracGhostResource. Useful as a placeholder.
Sourcepub proof fn alloc(value: T) -> tracked res : Self
pub proof fn alloc(value: T) -> tracked res : Self
TOTAL > 0,ensuresres.not_empty(),res.is_full(),res@ == value,res.wf(),Allocates a new FracGhostResource with the full fraction and the given value.
Sourcepub proof fn split_one(tracked &mut self) -> tracked res : FracGhost<T, TOTAL>
pub proof fn split_one(tracked &mut self) -> tracked res : FracGhost<T, TOTAL>
old(self).not_empty(),ensuresself.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.
Sourcepub proof fn split(tracked &mut self, n: int) -> tracked res : FracGhost<T, TOTAL>
pub proof fn split(tracked &mut self, n: int) -> tracked res : FracGhost<T, TOTAL>
1 <= n <= old(self).frac(),ensuresself.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.
Sourcepub proof fn combine(tracked &mut self, tracked other: FracGhost<T, TOTAL>)
pub proof fn combine(tracked &mut self, tracked other: FracGhost<T, TOTAL>)
old(self).id() == other.id(),other@ == old(self)@,ensuresold(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.
Sourcepub proof fn validate(tracked &self)
pub proof fn validate(tracked &self)
self.wf(),FracGhostResource satisfies the type invariant.
Sourcepub proof fn validate_full(tracked &self)
pub proof fn validate_full(tracked &self)
self.is_full(),ensuresself.not_empty(),self.frac() == TOTAL,self.wf(),