pub struct OneLeftOwner<A, B, const TOTAL: u64 = 2> { /* private fields */ }Expand description
OneLeftOwner is a special case of Left that the fraction is always one and it is the resource owner.
Implementations§
Source§impl<A, B, const TOTAL: u64> OneLeftOwner<A, B, TOTAL>
impl<A, B, const TOTAL: u64> OneLeftOwner<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 closed spec fn frac(self) -> int
pub closed spec fn frac(self) -> int
Returns the fraction of this token, which should always be 1.
Sourcepub closed spec fn has_resource(self) -> bool
pub closed spec fn has_resource(self) -> bool
Whether this token currently has the resource stored.
Sourcepub closed spec fn has_no_resource(self) -> bool
pub closed spec fn has_no_resource(self) -> bool
Whether the resource has been taken from this token.
Sourcepub open spec fn wf(self) -> bool
pub open spec fn wf(self) -> bool
{
&&& self.protocol_monoid().is_left()
&&& self.protocol_monoid().is_valid()
&&& self.protocol_monoid().is_resource_owner()
&&& self.frac() == 1
&&& TOTAL >= 1
&&& self.has_resource() <==> !self.has_no_resource()
}Type invariant.
Sourcepub proof fn validate(tracked &self)
pub proof fn validate(tracked &self)
ensures
self.wf(),OneLeftOwner token satisfies the type invariant.
Sourcepub proof fn validate_with_one_left_owner(tracked &mut self, tracked other: &Self)
pub proof fn validate_with_one_left_owner(tracked &mut self, tracked other: &Self)
ensures
*old(self) == *self,self.id() != other.id(),self.wf(),The existence of two OneLeftOwner tokens 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
requires
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
requires
old(self).has_resource(),ensuresres == old(self).resource(),self.has_no_resource(),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)
requires
old(self).has_no_resource(),ensuresself.resource() == a,self.has_resource(),self.wf(),Puts a resource of type A back to the 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>
ensures
self.resource() == a,self.has_resource(),self.wf(),res == if old(self).has_resource() { Some(old(self).resource()) } else { None },Updates the resource of type A in the token, and returns the old resource if available.
Auto Trait Implementations§
impl<A, B, const TOTAL: u64> Freeze for OneLeftOwner<A, B, TOTAL>
impl<A, B, const TOTAL: u64> RefUnwindSafe for OneLeftOwner<A, B, TOTAL>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B, const TOTAL: u64> Send for OneLeftOwner<A, B, TOTAL>
impl<A, B, const TOTAL: u64> Sync for OneLeftOwner<A, B, TOTAL>
impl<A, B, const TOTAL: u64> Unpin for OneLeftOwner<A, B, TOTAL>
impl<A, B, const TOTAL: u64> UnwindSafe for OneLeftOwner<A, B, TOTAL>where
A: UnwindSafe,
B: 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