pub struct CountGhostResource<T, const TOTAL: u64> { /* private fields */ }Expand description
A struct that stores and dispatches CountGhost<T>.
Unlike CountGhost, it provides an empty state.
It also remembers the value even it is empty.
Implementations§
Source§impl<T, const TOTAL: u64> CountGhostResource<T, TOTAL>
impl<T, const TOTAL: u64> CountGhostResource<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 CountGhostResource 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 CountGhostResource 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 CountGhostResource has the full fraction, i.e., TOTAL.
Sourcepub closed spec fn storage(self) -> CountGhost<T, TOTAL>
pub closed spec fn storage(self) -> CountGhost<T, TOTAL>
Returns the CountGhost<T,TOTAL> stored in this CountGhostResource.
Sourcepub closed spec fn view(self) -> T
pub closed spec fn view(self) -> T
Returns the value of type T stored in this CountGhostResource.
Sourcepub proof fn arbitrary() -> tracked res : Self
pub proof fn arbitrary() -> tracked res : Self
TOTAL > 0,Create an arbitrary CountGhostResource. 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 CountGhostResource with the full fraction and the given value.
Sourcepub proof fn split_one(tracked &mut self) -> tracked res : CountGhost<T, TOTAL>
pub proof fn split_one(tracked &mut self) -> tracked res : CountGhost<T, TOTAL>
old(self).not_empty(),ensuresfinal(self).id() == old(self).id(),final(self).frac() + 1 == old(self).frac(),final(self)@ == old(self)@,res.frac() == 1,res.id() == final(self).id(),res@ == final(self)@,old(self).frac() == 1 ==> final(self).is_empty(),final(self).wf(),Splits a CountGhost with fraction 1.
Sourcepub proof fn split(tracked &mut self, n: int) -> tracked res : CountGhost<T, TOTAL>
pub proof fn split(tracked &mut self, n: int) -> tracked res : CountGhost<T, TOTAL>
1 <= n <= old(self).frac(),ensuresfinal(self).id() == old(self).id(),final(self).frac() + n == old(self).frac(),final(self)@ == old(self)@,res.frac() == n,res.id() == final(self).id(),res@ == final(self)@,old(self).frac() == n ==> final(self).is_empty(),final(self).wf(),Splits a CountGhost with the given fraction.
Sourcepub proof fn combine(tracked &mut self, tracked other: CountGhost<T, TOTAL>)
pub proof fn combine(tracked &mut self, tracked other: CountGhost<T, TOTAL>)
old(self).id() == other.id(),other@ == old(self)@,ensuresold(self).frac() + other.frac() > TOTAL ==> false,old(self).frac() + other.frac() <= TOTAL
==> {
&&& final(self).id() == old(self).id()
&&& final(self)@ == old(self)@
&&& final(self).frac() == old(self).frac() + other.frac()
&&& final(self).wf()
},Combines a CountGhost.
Sourcepub proof fn validate(tracked &self)
pub proof fn validate(tracked &self)
self.wf(),CountGhostResource 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(),