pub struct CountGhostResource<T, const TOTAL: usize> { /* private fields */ }Expand description
A struct that stores and dispatches CountGhost<T>.
Unlike CountGhost, it provides an empty state: after all fractions have been split out,
it still remembers the resource value inside the carrier, mirroring CountResource.
Implementations§
Source§impl<T, const TOTAL: usize> CountGhostResource<T, TOTAL>
impl<T, const TOTAL: usize> CountGhostResource<T, TOTAL>
Sourcepub open spec fn wf(self) -> bool
pub open spec fn wf(self) -> bool
{
&&& TOTAL > 0
&&& 0 <= self.frac() <= TOTAL
&&& self.type_inv()
}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 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)@,!res.has_authority(),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)@,!res.has_authority(),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(),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)@ == other@
&&& 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_with_frac(tracked &self, tracked frac: &CountGhost<T, TOTAL>)
pub proof fn validate_with_frac(tracked &self, tracked frac: &CountGhost<T, TOTAL>)
self.id() == frac.id(),ensuresself@ == frac@,A CountGhostResource and a CountGhost with the same id agree on the value.
Unlike CountGhost::agree, this works even when the resource is empty (all fractions split out).