pub struct Left<A, B, const TOTAL: u64 = 2> { /* private fields */ }Expand description
Left ensures the resource is of type A.
Implementations§
Source§impl<A, B, const TOTAL: u64> Left<A, B, TOTAL>
impl<A, B, const TOTAL: u64> Left<A, B, TOTAL>
Sourcepub closed spec fn protocol_monoid(self) -> CsumP<A, B, TOTAL>
pub closed spec fn protocol_monoid(self) -> CsumP<A, B, TOTAL>
The underlying protocol monoid value for this resource.
Sourcepub open spec fn is_resource_owner(self) -> bool
pub open spec fn is_resource_owner(self) -> bool
{ self.protocol_monoid().is_resource_owner() }Whether this token has the right to access the underlying resource.
Sourcepub open spec fn resource(self) -> A
pub open spec fn resource(self) -> A
{ self.protocol_monoid().resource()->Left_0 }The resource value, only meaningful if is_resource_owner is true.
Sourcepub open spec fn wf(self) -> bool
pub open spec fn wf(self) -> bool
{
&&& self.protocol_monoid().is_left()
&&& self.protocol_monoid().is_valid()
&&& 1 <= self.frac() <= TOTAL
&&& self.is_resource_owner() ==> (self.has_resource() <==> !self.has_no_resource())
}Type invariant.
Sourcepub open spec fn has_resource(self) -> bool
pub open spec fn has_resource(self) -> bool
{ self.protocol_monoid().has_resource() }Whether the resource is currently stored, only meaningful if is_resource_owner is true.
Sourcepub open spec fn has_no_resource(self) -> bool
pub open spec fn has_no_resource(self) -> bool
{ self.protocol_monoid().has_no_resource() }Whether the resource has been taken, only meaningful if is_resource_owner is true.
Sourcepub open spec fn frac(self) -> int
pub open spec fn frac(self) -> int
{ self.protocol_monoid().frac() }The fraction this token represents.
Sourcepub proof fn validate(tracked &self)
pub proof fn validate(tracked &self)
self.wf(),Left token satisfies the type invariant.
Sourcepub proof fn validate_with_left(tracked &mut self, tracked other: &Self)
pub proof fn validate_with_left(tracked &mut self, tracked other: &Self)
old(self).id() == other.id(),ensures*old(self) == *self,!(self.is_resource_owner() && other.is_resource_owner()),self.frac() + other.frac() <= TOTAL,self.wf(),The existence of two Left tokens with the same id ensures at most one of them is the resource owner.
Sourcepub proof fn validate_with_right(tracked &self, tracked other: &Right<A, B, TOTAL>)
pub proof fn validate_with_right(tracked &self, tracked other: &Right<A, B, TOTAL>)
self.id() != other.id(),self.wf(),The existence of a Right token ensures they can not have the same id.
Sourcepub proof fn tracked_borrow(tracked &self) -> tracked res : &A
pub proof fn tracked_borrow(tracked &self) -> tracked res : &A
self.has_resource(),ensures*res == self.resource(),Borrows the resource of type A.
Sourcepub proof fn take_resource(tracked &mut self) -> tracked res : A
pub proof fn take_resource(tracked &mut self) -> tracked res : A
old(self).is_resource_owner(),old(self).has_resource(),ensuresself.id() == old(self).id(),res == old(self).resource(),self.is_resource_owner(),self.has_no_resource(),self.frac() == old(self).frac(),self.wf(),Takes the resource out of the token.
Sourcepub proof fn put_resource(tracked &mut self, tracked a: A)
pub proof fn put_resource(tracked &mut self, tracked a: A)
old(self).is_resource_owner(),old(self).has_no_resource(),ensuresself.id() == old(self).id(),self.protocol_monoid() == CsumP::<A, B, TOTAL>::Cinl(Some(a), self.frac(), true),self.is_resource_owner(),self.has_resource(),self.resource() == a,self.frac() == old(self).frac(),self.wf(),Puts a resource of type A back to the token.
Sourcepub proof fn split_with_resource(tracked &mut self, n: int) -> tracked res : Self
pub proof fn split_with_resource(tracked &mut self, n: int) -> tracked res : Self
0 < n < old(self).frac(),ensuresself.id() == old(self).id(),res.id() == self.id(),self.frac() == old(self).frac() - n,res.frac() == n,!self.is_resource_owner(),res.is_resource_owner() <==> old(self).is_resource_owner(),res.is_resource_owner() ==> (res.has_resource() <==> old(self).has_resource()),res.has_resource() ==> res.resource() == old(self).resource(),self.wf(),res.wf(),Splits this token into two Left tokens with the given fraction n, given the resource to the new token if available.
Sourcepub proof fn split_without_resource(tracked &mut self, n: int) -> tracked res : Self
pub proof fn split_without_resource(tracked &mut self, n: int) -> tracked res : Self
0 < n < old(self).frac(),ensuresself.id() == old(self).id(),res.id() == self.id(),self.frac() == old(self).frac() - n,res.frac() == n,!res.is_resource_owner(),self.is_resource_owner() <==> old(self).is_resource_owner(),self.is_resource_owner() ==> (self.has_resource() <==> old(self).has_resource()),self.has_resource() ==> self.resource() == old(self).resource(),self.wf(),res.wf(),Splits this token into two Left tokens with the given fraction n, without giving the resource to the new token.
Sourcepub proof fn update(tracked &mut self, tracked a: A) -> tracked res : Option<A>
pub proof fn update(tracked &mut self, tracked a: A) -> tracked res : Option<A>
old(self).is_resource_owner(),ensuresself.id() == old(self).id(),self.is_resource_owner(),self.has_resource(),self.resource() == a,self.frac() == old(self).frac(),res == if old(self).has_resource() { Some(old(self).resource()) } else { None },self.wf(),Updates the token with a new resource of type A, and returns the old resource if available.