pub struct Gate {
pub id: String,
pub severity: Severity,
pub outcome: Outcome,
}Expand description
One contract: an identifier, a severity and an outcome.
Fields§
§id: StringStable identifier, e.g. "rdap-reachable".
severity: SeverityWhether this gate can halt the run.
outcome: OutcomeThe evaluated outcome.
Implementations§
Source§impl Gate
impl Gate
Sourcepub fn new(id: impl Into<String>, outcome: Outcome) -> Self
pub fn new(id: impl Into<String>, outcome: Outcome) -> Self
A blocking gate with an explicit outcome.
Sourcepub fn fail(id: impl Into<String>, reason: impl Into<String>) -> Self
pub fn fail(id: impl Into<String>, reason: impl Into<String>) -> Self
A blocking gate that failed, with the reason.
Sourcepub fn unevaluable(id: impl Into<String>, reason: impl Into<String>) -> Self
pub fn unevaluable(id: impl Into<String>, reason: impl Into<String>) -> Self
A blocking gate that could not be checked, with the reason.
Sourcepub fn check(
id: impl Into<String>,
held: bool,
reason: impl Into<String>,
) -> Self
pub fn check( id: impl Into<String>, held: bool, reason: impl Into<String>, ) -> Self
Build a gate from a boolean check, with the reason used when it is false.
use gate_contract::Gate;
let g = Gate::check("page-count-nonzero", 12 > 0, "no pages were produced");
assert!(g.outcome.passed());Sourcepub fn check_known<T, F>(
id: impl Into<String>,
value: &Known<T>,
predicate: F,
reason: impl Into<String>,
) -> Self
pub fn check_known<T, F>( id: impl Into<String>, value: &Known<T>, predicate: F, reason: impl Into<String>, ) -> Self
Build a gate from a value that may be unknown.
Known(v) is handed to predicate; Unknown short-circuits to
Outcome::Unevaluable, which is what makes the missing input halt a blocking
gate instead of silently passing it.
use gate_contract::{Gate, Known, Outcome};
let measured: Known<u32> = Known::Unknown;
let g = Gate::check_known("coverage-above-floor", &measured, |c| *c >= 50, "below floor");
assert!(matches!(g.outcome, Outcome::Unevaluable(_)));Trait Implementations§
impl Eq for Gate
impl StructuralPartialEq for Gate
Auto Trait Implementations§
impl Freeze for Gate
impl RefUnwindSafe for Gate
impl Send for Gate
impl Sync for Gate
impl Unpin for Gate
impl UnsafeUnpin for Gate
impl UnwindSafe for Gate
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