pub struct AtomicInvariant<T>(/* private fields */);Implementations§
Source§impl<T: Protocol> AtomicInvariant<T>
impl<T: Protocol> AtomicInvariant<T>
Sourcepub fn new(
value: Ghost<T>,
public: Snapshot<T::Public>,
namespace: Snapshot<Namespace>,
) -> Ghost<Self>
pub fn new( value: Ghost<T>, public: Snapshot<T::Public>, namespace: Snapshot<Namespace>, ) -> Ghost<Self>
Construct a AtomicInvariant
§Parameters
value: the actual data contained in the invariant. UseSelf::opento access it. Also called the ‘private’ part of the invariant.public: the ‘public’ part of the invariant.namespace: the namespace of the invariant. This is required to avoid opening the same invariant twice.
requires
value.protocol(*public)ensures
result.public() == *publicensures
result.namespace() == *namespaceterminates
ghost
Sourcepub fn namespace(self) -> Namespace
pub fn namespace(self) -> Namespace
Get the namespace associated with this invariant.
logic(opaque) ⚠
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Gives the actual invariant held by the AtomicInvariant.
ensures
result.protocol(self.public())terminates
ghost
Sourcepub fn open<A>(
&self,
tokens: Tokens<'_>,
f: impl FnGhost + for<'a> FnOnce(&'a mut T) -> A,
) -> A
pub fn open<A>( &self, tokens: Tokens<'_>, f: impl FnGhost + for<'a> FnOnce(&'a mut T) -> A, ) -> A
Open the invariant to get the data stored inside.
This will call the closure f with the inner data. You must restore the
contained Protocol before returning from the closure.
NOTE: This function can only be called from ghost code, because atomic
invariants are always wrapped in Ghost. This guarantees atomicity.
requires
tokens.contains(self.namespace())requires
forall<t: &mut T> t.protocol(self.public()) && inv(t) ==> f.precondition((t,)) && // f must restore the invariant (forall<res: A> f.postcondition_once((t,), res) ==> (^t).protocol(self.public()))
ensures
exists<t: &mut T> inv(t) && t.protocol(self.public()) && f.postcondition_once((t,), result)
terminates
ghost
Trait Implementations§
impl<T: Send> Sync for AtomicInvariant<T>
Auto Trait Implementations§
impl<T> Freeze for AtomicInvariant<T>
impl<T> RefUnwindSafe for AtomicInvariant<T>where
T: RefUnwindSafe,
impl<T> !Send for AtomicInvariant<T>
impl<T> Unpin for AtomicInvariant<T>
impl<T> UnsafeUnpin for AtomicInvariant<T>
impl<T> UnwindSafe for AtomicInvariant<T>where
T: RefUnwindSafe,
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