pub struct LocalInvariant<T: Protocol> { /* private fields */ }Expand description
A ghost structure, that holds a piece of data (T) together with an
protocol.
Implementations§
Source§impl<T: Protocol> LocalInvariant<T>
impl<T: Protocol> LocalInvariant<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 LocalInvariant
§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 open<'a, A>(
this: Ghost<&'a Self>,
tokens: Ghost<Tokens<'a>>,
f: impl FnOnce(Ghost<&'a mut T>) -> A,
) -> A
pub fn open<'a, A>( this: Ghost<&'a Self>, tokens: Ghost<Tokens<'a>>, f: impl FnOnce(Ghost<&'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.
requires
tokens.contains(this.namespace())requires
forall<t: Ghost<&mut T>> t.protocol(this.public()) && inv(t) ==> f.precondition((t,)) && // f must restore the invariant (forall<res: A> f.postcondition_once((t,), res) ==> (^t).protocol(this.public()))
ensures
exists<t: Ghost<&mut T>> t.protocol(this.public()) && f.postcondition_once((t,), result)
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. This allows reentrant access to the invariant.
requires
tokens.contains(self.namespace())ensures
result.protocol(self.public())terminates
ghost
Auto Trait Implementations§
impl<T> !Freeze for LocalInvariant<T>
impl<T> !RefUnwindSafe for LocalInvariant<T>
impl<T> Send for LocalInvariant<T>where
T: Send,
impl<T> !Sync for LocalInvariant<T>
impl<T> Unpin for LocalInvariant<T>where
T: Unpin,
impl<T> UnwindSafe for LocalInvariant<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