Skip to main content

PreparedOutcome

Enum PreparedOutcome 

Source
#[non_exhaustive]
pub enum PreparedOutcome { Valid, Invalid(Vec<ViolationDraft>), }
Expand description

The type-erased result produced before rule identity is attached.

§Examples

use qubit_validator::{PreparedOutcome, ViolationCode, ViolationDraft};

let accepted = PreparedOutcome::valid();
let rejected = PreparedOutcome::invalid(vec![
    ViolationDraft::new(ViolationCode::new("text.blank")),
])?;
assert!(matches!(accepted, PreparedOutcome::Valid));
assert!(matches!(rejected, PreparedOutcome::Invalid(drafts) if drafts.len() == 1));

The caller’s orchestration policy records missing inputs and failed prerequisites as skipped ValidationOutcome values.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Valid

Input is valid.

§

Invalid(Vec<ViolationDraft>)

Input is invalid with draft violations.

Tuple Fields

§0: Vec<ViolationDraft>

One or more safe draft violations produced by the validator.

Implementations§

Source§

impl PreparedOutcome

Source

pub const fn valid() -> Self

Creates a successful prepared outcome.

§Returns

A prepared outcome representing valid input.

Examples found in repository?
examples/validate_named_bench.rs (line 48)
43    fn validate(
44        &self,
45        _: ValidationValue<'_>,
46        _: &BoundValidationContext<'_>,
47    ) -> Result<PreparedOutcome, ExecutionError> {
48        Ok(PreparedOutcome::valid())
49    }
Source

pub fn invalid( violations: Vec<ViolationDraft>, ) -> Result<Self, ValidationOutcomeError>

Creates an invalid prepared outcome with one or more violation drafts.

§Parameters
  • violations: Draft violations to include in the outcome.
§Returns

The invalid prepared outcome containing violations.

§Errors

Returns ValidationOutcomeError::EmptyViolations when violations is empty.

Source

pub fn into_bound( self, rule_id: ValidatorId, ) -> Result<ValidationOutcome, ValidationOutcomeError>

Attaches a bound rule identity to draft violations.

§Parameters
  • rule_id: Identity of the rule that produced these violations.
§Returns

The corresponding bound validation outcome.

§Errors

Returns ValidationOutcomeError::EmptyViolations when an invalid result has no drafts.

Trait Implementations§

Source§

impl Debug for PreparedOutcome

Source§

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

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

impl Eq for PreparedOutcome

Source§

impl PartialEq for PreparedOutcome

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PreparedOutcome

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.