pub enum QuantorError {
PredicateFailed {
kind: QuantorKind,
index: usize,
},
EmptyInput {
kind: QuantorKind,
},
NoMatch {
kind: QuantorKind,
},
UnexpectedMatch {
kind: QuantorKind,
index: usize,
},
NotAllEqual {
kind: QuantorKind,
index: usize,
},
PairwiseFailed {
kind: QuantorKind,
index: usize,
},
ForAllExistsFailed {
kind: QuantorKind,
outer_index: usize,
},
ExistsForAllFailed {
kind: QuantorKind,
outer_index: usize,
},
ExactlyNFailed {
kind: QuantorKind,
found: usize,
expected: usize,
},
Custom(&'static str),
}
Expand description
Error type returned by fallible quantifier evaluations in quantor
.
Variants§
PredicateFailed
Returned when a predicate fails during a forall
check.
Fields
kind: QuantorKind
The kind of quantifier that threw this error.
EmptyInput
Returned when no elements are given.
Fields
kind: QuantorKind
The kind of quantifier that threw this error.
NoMatch
Returned when no element satisfies the predicate in an exists
check.
Fields
kind: QuantorKind
The kind of quantifier that threw this error.
UnexpectedMatch
Returned when none
or exactly_one
fails.
Fields
kind: QuantorKind
The kind of quantifier that threw this error.
NotAllEqual
Returned when not all elements are equal in all_equal
.
Fields
kind: QuantorKind
The kind of quantifier that threw this error.
PairwiseFailed
Returned when a pair of adjacent elements fail a pairwise
predicate.
Fields
kind: QuantorKind
The kind of quantifier that threw this error.
ForAllExistsFailed
Returned when a forallexists
condition fails.
Fields
kind: QuantorKind
The kind of quantifier that threw this error.
ExistsForAllFailed
Returned when no left-side element satisfies the existsforall
condition.
Fields
kind: QuantorKind
The kind of quantifier that threw this error.
ExactlyNFailed
Returned when the number of matches does not equal the expected count.
Fields
kind: QuantorKind
The kind of quantifier that threw this error.
Custom(&'static str)
A catch-all error with a static message.
Implementations§
Source§impl QuantorError
impl QuantorError
Sourcepub fn is_predicate_failed(&self) -> bool
pub fn is_predicate_failed(&self) -> bool
Returns true
if the quantifier failed due to a predicate mismatch.
Useful for identifying simple predicate failures, such as those from forall
or exactly_one
.
§Returns
true
if the error variant isQuantorError::PredicateFailed
.false
otherwise.
§Example
use quantor::{forall, error::QuantorResultExt};
let nums = vec![1, 2, 3];
let result = forall(&nums, |x| *x < 3);
assert!(result.is_err());
assert!(result.unwrap_err().is_predicate_failed());
Sourcepub fn is_no_match(&self) -> bool
pub fn is_no_match(&self) -> bool
Returns true
if the quantifier failed because no element matched the predicate.
Typically used with exists
or existsforall
where at least one match is expected.
§Returns
true
if the error variant isQuantorError::NoMatch
.false
otherwise.
§Example
use quantor::{exists, error::QuantorResultExt};
let nums = [1, 2, 3];
let result = exists(&nums, |x| *x > 10);
assert!(result.is_err());
assert!(result.unwrap_err().is_no_match());
Sourcepub fn kind(&self) -> QuantorKind
pub fn kind(&self) -> QuantorKind
Returns the QuantorKind
associated with this error.
Allows inspection of which quantifier failed, regardless of the specific error variant.
§Returns
- A
QuantorKind
value corresponding to the quantifier that produced the error. QuantorKind::Custom
for generic errors.
§Example
use quantor::{forall, error::{QuantorKind, QuantorResultExt}};
let nums = [1, 2, 3];
let result = forall(&nums, |x| *x > 3);
assert_eq!(result.unwrap_err().kind(), QuantorKind::Forall);