pub trait Verify{
// Required method
fn verify(&self) -> Result<(), <Self as Stateful>::Error>;
// Provided methods
fn assume_verified(&self) { ... }
fn is_verified(&self) -> bool { ... }
fn apply(
self,
f: impl FnMut(&mut Self),
) -> Result<Self, <Self as Stateful>::Error> { ... }
}Expand description
TODO move to verifiable crate, and make stateful dependent on it.
Trait implemented by stateful structs or enumerations for which
certain invariants must be held and can be verified at runtime.
You can #[derive(Verify)] if all fields of your structure satisfy
verify, in which case the error will be Box
Required Methods§
Provided Methods§
Sourcefn assume_verified(&self)
fn assume_verified(&self)
§Panic
Panics when the structure is not in a valid state.
fn is_verified(&self) -> bool
Sourcefn apply(
self,
f: impl FnMut(&mut Self),
) -> Result<Self, <Self as Stateful>::Error>
fn apply( self, f: impl FnMut(&mut Self), ) -> Result<Self, <Self as Stateful>::Error>
Applies the given closure, returning the object back to the user if it is at a valid state after the closure is applied to it, and consuming it if the closure left it at an invalid state.
The example assume that at the default state the object is valid.
§Example
use std::mem; match value.apply(mem::take(&mut obj), |obj| *obj += 1 ) { Ok(obj) => { *obj = obj }, Err(e) => { } }
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.