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.
(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
Sourcepub fn open_const<'a>(&'a self, tokens: &'a Tokens<'_>) -> &'a T
pub fn open_const<'a>(&'a self, tokens: &'a Tokens<'_>) -> &'a T
Open the invariant to get the data stored inside, immutably.
NOTE: This is the counterpart of NonAtomicInvariant::open_const, but
it is not expected to be useful in practice as atomicity prevents
re-entrancy anyway.
requires
tokens.contains(self.namespace())ensures
result.protocol(self.public())terminates
ghost