pub struct Exclusive<T> { /* private fields */ }Expand description
Exclusive is a token that stores a tracked object of type T and ensures its exclusive ownership.
No two Exclusive tokens can have the same id.
The owned tracked object can be borrowed, updated, taken out and put back.
Implementations§
Source§impl<T> Exclusive<T>
impl<T> Exclusive<T>
Sourcepub closed spec fn protocol_monoid(self) -> ExclP<T>
pub closed spec fn protocol_monoid(self) -> ExclP<T>
Returns the underlying ExclP<T> protocol monoid.
Sourcepub open spec fn resource(self) -> T
pub open spec fn resource(self) -> T
{ self.protocol_monoid().value() }Returns the owned resource.
Sourcepub open spec fn has_resource(self) -> bool
pub open spec fn has_resource(self) -> bool
{ self.protocol_monoid()->Excl_0 is Some }Wether the token stores a resource.
Sourcepub open spec fn has_no_resource(self) -> bool
pub open spec fn has_no_resource(self) -> bool
{ self.protocol_monoid()->Excl_0 is None }Wether the token does not store any resource.
Sourcepub proof fn validate_with_other(tracked &mut self, tracked other: &Self)
pub proof fn validate_with_other(tracked &mut self, tracked other: &Self)
ensures
*old(self) == *self,self.wf(),self.id() != other.id(),The existence of two Exclusive tokens ensures that they do not have the same id.
Sourcepub proof fn tracked_borrow(tracked &self) -> tracked res : &T
pub proof fn tracked_borrow(tracked &self) -> tracked res : &T
requires
self.has_resource(),ensures*res == self.resource(),Borrows the owned resource.
Sourcepub proof fn take_resource(tracked &mut self) -> tracked res : T
pub proof fn take_resource(tracked &mut self) -> tracked res : T
requires
old(self).has_resource(),ensuresself.has_no_resource(),res == old(self).resource(),self.wf(),Takes out the owned resource.
Sourcepub proof fn put_resource(tracked &mut self, tracked value: T)
pub proof fn put_resource(tracked &mut self, tracked value: T)
requires
old(self).has_no_resource(),ensuresself.has_resource(),self.resource() == value,self.wf(),Puts back the owned resource.
Sourcepub proof fn update(tracked &mut self, tracked value: T) -> tracked res : Option<T>
pub proof fn update(tracked &mut self, tracked value: T) -> tracked res : Option<T>
ensures
self.has_resource(),self.resource() == value,res == if old(self).has_resource() { Some(old(self).resource()) } else { None },self.wf(),Updates the owned resource and returns the old resource if it exists.
Auto Trait Implementations§
impl<T> Freeze for Exclusive<T>
impl<T> RefUnwindSafe for Exclusive<T>where
T: RefUnwindSafe,
impl<T> Send for Exclusive<T>
impl<T> Sync for Exclusive<T>
impl<T> Unpin for Exclusive<T>where
T: Unpin,
impl<T> UnwindSafe for Exclusive<T>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