pub struct Count<T, const TOTAL: usize = 2> { /* private fields */ }Implementations§
Source§impl<T, const TOTAL: usize> Count<T, TOTAL>
impl<T, const TOTAL: usize> Count<T, TOTAL>
Whether this token carries the unique authority for taking/updating the resource.
Sourcepub open spec fn valid(self, id: Loc, frac: int) -> bool
pub open spec fn valid(self, id: Loc, frac: int) -> bool
{
&&& self.id() == id
&&& self.frac() == frac
}Sourcepub proof fn alloc(tracked v: T) -> tracked result : Self
pub proof fn alloc(tracked v: T) -> tracked result : Self
requires
TOTAL > 0,ensuresresult.frac() == TOTAL,result.resource() == v,result.has_authority(),Allocates a new Count with the full fraction and the given resource value.
Sourcepub proof fn agree(tracked &self, tracked other: &Self)
pub proof fn agree(tracked &self, tracked other: &Self)
requires
self.id() == other.id(),ensuresself.resource() == other.resource(),Two Counts with the same id must have the same resource value.
Sourcepub proof fn split(tracked &mut self, n: int) -> tracked result : Self
pub proof fn split(tracked &mut self, n: int) -> tracked result : Self
requires
0 < n < old(self).frac(),ensuresresult.id() == final(self).id(),final(self).id() == old(self).id(),final(self).resource() == old(self).resource(),result.resource() == old(self).resource(),final(self).frac() + result.frac() == old(self).frac(),result.frac() == n,final(self).has_authority() == old(self).has_authority(),!result.has_authority(),Splits another fraction n from this Count, returning a new Count with that fraction.
Sourcepub proof fn combine(tracked &mut self, tracked other: Self)
pub proof fn combine(tracked &mut self, tracked other: Self)
requires
old(self).id() == other.id(),ensuresfinal(self).id() == old(self).id(),final(self).resource() == old(self).resource(),final(self).resource() == other.resource(),final(self).frac() == old(self).frac() + other.frac(),final(self).has_authority() == (old(self).has_authority() || other.has_authority()),Combines another Count into this one, consuming the other Count.
Sourcepub proof fn bounded(tracked &self)
pub proof fn bounded(tracked &self)
ensures
0 < self.frac() <= TOTAL,The fraction of the resource must be positive and at most TOTAL.
Sourcepub proof fn tracked_borrow(tracked &self) -> tracked ret : &T
pub proof fn tracked_borrow(tracked &self) -> tracked ret : &T
returns
self.resource(),Borrows the resource value.
Sourcepub proof fn take_resource(tracked self) -> tracked (T, EmptyCount<T, TOTAL>)
pub proof fn take_resource(tracked self) -> tracked (T, EmptyCount<T, TOTAL>)
requires
self.frac() == TOTAL,self.has_authority(),ensuresresource == self.resource(),empty.id() == self.id(),Consumes the Count and returns the resource value and an EmptyCount with the same id.
Sourcepub proof fn into_resource(tracked self) -> tracked res : T
pub proof fn into_resource(tracked self) -> tracked res : T
requires
self.frac() == TOTAL,self.has_authority(),returnsself.resource(),Consumes the Count and returns the resource value, the id is lost because the EmptyCount is not returned.
Auto Trait Implementations§
impl<T, const TOTAL: usize> Freeze for Count<T, TOTAL>
impl<T, const TOTAL: usize> RefUnwindSafe for Count<T, TOTAL>where
T: RefUnwindSafe,
impl<T, const TOTAL: usize> Send for Count<T, TOTAL>
impl<T, const TOTAL: usize> Sync for Count<T, TOTAL>
impl<T, const TOTAL: usize> Unpin for Count<T, TOTAL>where
T: Unpin,
impl<T, const TOTAL: usize> UnsafeUnpin for Count<T, TOTAL>
impl<T, const TOTAL: usize> UnwindSafe for Count<T, TOTAL>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more