Enum QuantorError

Source
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.

§index: usize

The index of the first failing element.

§

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.

§index: usize

The index of the violating element.

§

NotAllEqual

Returned when not all elements are equal in all_equal.

Fields

§kind: QuantorKind

The kind of quantifier that threw this error.

§index: usize

The index of the first element that is not equal to the other, previously checked elements.

§

PairwiseFailed

Returned when a pair of adjacent elements fail a pairwise predicate.

Fields

§kind: QuantorKind

The kind of quantifier that threw this error.

§index: usize

The index of the first element in the failing pair.

§

ForAllExistsFailed

Returned when a forallexists condition fails.

Fields

§kind: QuantorKind

The kind of quantifier that threw this error.

§outer_index: usize

The index of the outer (left) element that failed.

§

ExistsForAllFailed

Returned when no left-side element satisfies the existsforall condition.

Fields

§kind: QuantorKind

The kind of quantifier that threw this error.

§outer_index: usize

The index of the outer (left) element that failed.

§

ExactlyNFailed

Returned when the number of matches does not equal the expected count.

Fields

§kind: QuantorKind

The kind of quantifier that threw this error.

§found: usize

Number of matches found.

§expected: usize

Number of matches expected.

§

Custom(&'static str)

A catch-all error with a static message.

Implementations§

Source§

impl QuantorError

Source

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
§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());
Source

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
§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());
Source

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
§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);

Trait Implementations§

Source§

impl Debug for QuantorError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for QuantorError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for QuantorError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<&'static str> for QuantorError

Source§

fn from(msg: &'static str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for QuantorError

Source§

fn from(msg: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for QuantorError

Source§

fn eq(&self, other: &QuantorError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for QuantorError

Source§

impl StructuralPartialEq for QuantorError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.