Skip to main content

ValidationErrors

Struct ValidationErrors 

Source
pub struct ValidationErrors { /* private fields */ }
Expand description

A non-empty collection of ValidationErrors, rendered as a Pydantic-style report.

Extends the Pydantic report with:

  • fitness — Van der Aalst alignment conformance score
  • variant_id — fingerprint for recurring failure patterns
  • by_section — object-centric grouping
2 validation errors for Server
host
  must not be empty (got: `""`) [empty]
port
  input must be in range 1..=65535 (got: `0`) [out_of_range]

Implementations§

Source§

impl ValidationErrors

Source

pub fn errors(&self) -> &[ValidationError]

The individual errors, in the order they were discovered (depth-first).

Source

pub fn len(&self) -> usize

Number of collected errors (always ≥ 1).

Source

pub fn is_empty(&self) -> bool

Always falseValidationErrors only exists when there is ≥ 1 error.

Source

pub fn title(&self) -> Option<&str>

The model/type name this report is about, if set.

Source

pub fn set_title_for<T: ?Sized>(&mut self)

Set the report title to the short name of T (e.g. ServerConfig).

Source

pub fn has_fatal(&self) -> bool

Whether any error is Severity::Fatal (requires immediate halt).

Source

pub fn errors_above( &self, min: Severity, ) -> impl Iterator<Item = &ValidationError>

Errors at or above the given severity threshold.

Source

pub fn fitness(&self) -> f64

Van der Aalst alignment fitness — proportion of checks that passed.

Returns 1.0 when all checks pass (no errors), 0.0 when every check failed. Analogous to the replay-fitness metric from conformance checking: how well does the observed config align to the declared validation model?

§Example
use star_toml::{Validate, Validator};

struct Pair { a: u32, b: u32 }
impl Validate for Pair {
    fn validate(&self, v: &mut Validator) {
        v.check_range("a", self.a, 1..=10);  // passes
        v.check_range("b", self.b, 1..=10);  // fails
    }
}
let errs = Pair { a: 5, b: 0 }.check().unwrap_err();
assert_eq!(errs.fitness(), 0.5);  // 1 of 2 checks passed
Source

pub fn variant_id(&self) -> u64

Variant fingerprint — a deterministic hash of the failure pattern.

Two ValidationErrors instances with the same set of (location, code) pairs produce the same variant ID, regardless of message text or input values. Useful for deduplicating recurring failure patterns across runs.

Uses FNV-1a over the sorted "loc:code" pairs.

Source

pub fn by_section(&self) -> BTreeMap<String, Vec<&ValidationError>>

Object-centric grouping — errors indexed by their top-level config section.

Implements Van der Aalst’s object-centric view: each top-level TOML table is an “object type”; this groups all its constraint violations together.

Root-level errors are keyed "(root)".

Trait Implementations§

Source§

impl Clone for ValidationErrors

Source§

fn clone(&self) -> ValidationErrors

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ValidationErrors

Source§

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

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

impl Display for ValidationErrors

Source§

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

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

impl Eq for ValidationErrors

Source§

impl Error for ValidationErrors

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<ValidationErrors> for Error

Source§

fn from(source: ValidationErrors) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ValidationErrors

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for ValidationErrors

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.