Exclusive

Struct Exclusive 

Source
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>

Source

pub closed spec fn id(self) -> Loc

Returns the unique identifier.

Source

pub closed spec fn protocol_monoid(self) -> ExclP<T>

Returns the underlying ExclP<T> protocol monoid.

Source

pub open spec fn resource(self) -> T

{ self.protocol_monoid().value() }

Returns the owned resource.

Source

pub open spec fn wf(self) -> bool

{ self.protocol_monoid() is Excl }

Type invariant.

Source

pub open spec fn has_resource(self) -> bool

{ self.protocol_monoid()->Excl_0 is Some }

Wether the token stores a resource.

Source

pub open spec fn has_no_resource(self) -> bool

{ self.protocol_monoid()->Excl_0 is None }

Wether the token does not store any resource.

Source

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.

Source

pub proof fn tracked_borrow(tracked &self) -> tracked res : &T

requires
self.has_resource(),
ensures
*res == self.resource(),

Borrows the owned resource.

Source

pub proof fn take_resource(tracked &mut self) -> tracked res : T

requires
old(self).has_resource(),
ensures
self.has_no_resource(),
res == old(self).resource(),
self.wf(),

Takes out the owned resource.

Source

pub proof fn put_resource(tracked &mut self, tracked value: T)

requires
old(self).has_no_resource(),
ensures
self.has_resource(),
self.resource() == value,
self.wf(),

Puts back the owned resource.

Source

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>
where T: Send + Sync,

§

impl<T> Sync for Exclusive<T>
where T: Sync + Send,

§

impl<T> Unpin for Exclusive<T>
where T: Unpin,

§

impl<T> UnwindSafe for Exclusive<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, VERUS_SPEC__A> FromSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: From<T>,

§

fn obeys_from_spec() -> bool

§

fn from_spec(v: T) -> VERUS_SPEC__A

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, VERUS_SPEC__A> IntoSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: Into<T>,

§

fn obeys_into_spec() -> bool

§

fn into_spec(self) -> T

§

impl<T, U> IntoSpecImpl<U> for T
where U: From<T>,

§

fn obeys_into_spec() -> bool

§

fn into_spec(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, VERUS_SPEC__A> TryFromSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: TryFrom<T>,

§

fn obeys_try_from_spec() -> bool

§

fn try_from_spec( v: T, ) -> Result<VERUS_SPEC__A, <VERUS_SPEC__A as TryFrom<T>>::Error>

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T, VERUS_SPEC__A> TryIntoSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: TryInto<T>,

§

fn obeys_try_into_spec() -> bool

§

fn try_into_spec(self) -> Result<T, <VERUS_SPEC__A as TryInto<T>>::Error>

§

impl<T, U> TryIntoSpecImpl<U> for T
where U: TryFrom<T>,

§

fn obeys_try_into_spec() -> bool

§

fn try_into_spec(self) -> Result<U, <U as TryFrom<T>>::Error>