pub trait CheckProtocol {
// Required method
fn enforce_law(&self) -> Result<(), ConstitutionError>;
}Expand description
Protocol for enforcing constitutional invariants (runtime checks).
Types implementing this trait can validate their internal state against
a set of invariants defined via the #[derive(Constitution)] macro.
Required Methods§
Sourcefn enforce_law(&self) -> Result<(), ConstitutionError>
fn enforce_law(&self) -> Result<(), ConstitutionError>
Enforces all invariants, returning an error if any are violated.
§Returns
Ok(())if all invariants are satisfiedErr(ConstitutionError)containing a description of the violated invariant
§Example
ⓘ
use praborrow_core::CheckProtocol;
let data = MyStruct { value: -1 };
match data.enforce_law() {
Ok(()) => println!("All invariants satisfied"),
Err(e) => println!("Invariant violated: {}", e),
}