Skip to main content

ValidationReport

Struct ValidationReport 

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

A collection of validation results: errors, warnings, and informational notes.

Enables batch validation where all issues are collected instead of failing on the first error. Produced by crate::validator::ValidationContext methods such as validate_lenient and validate_lenient_grouped.

§Building reports manually

Use ValidationReport::from_issues to construct a report from pre-built issue vectors, or the add_* methods to push individual issues:

use edifact_rs::{ValidationReport, ValidationIssue, ValidationSeverity};

let mut report = ValidationReport::default();
report.add_warning(
    ValidationIssue::new(ValidationSeverity::Warning, "optional field missing")
        .with_segment("DTM"),
);
assert!(report.is_valid()); // warnings don't fail validation

Implementations§

Source§

impl ValidationReport

Source

pub fn from_issues( errors: Vec<ValidationIssue>, warnings: Vec<ValidationIssue>, infos: Vec<ValidationIssue>, ) -> ValidationReport

Construct a report directly from pre-categorized issue vectors.

This is the primary escape hatch for code that needs to inject advisory issues into a report outside the normal validation pipeline — for example, a middleware layer that wants to attach AHB-layer skip notices without registering a synthetic ProfileRulePack rule.

§Example
let mut report = ctx.validate_lenient(&segments);
let advisory = ValidationReport::from_issues(
    vec![],
    vec![ValidationIssue::new(ValidationSeverity::Warning, "AHB layer skipped")
        .with_rule_id("AHB-SKIP-001")],
    vec![],
);
report.merge(advisory);
Source

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

Returns all error-level ValidationIssues in this report.

Source

pub fn errors_mut(&mut self) -> &mut [ValidationIssue]

Returns all error-level ValidationIssues mutably.

Source

pub fn warnings(&self) -> &[ValidationIssue]

Returns all warning-level ValidationIssues in this report.

Source

pub fn warnings_mut(&mut self) -> &mut [ValidationIssue]

Returns all warning-level ValidationIssues mutably.

Source

pub fn infos(&self) -> &[ValidationIssue]

Returns all informational ValidationIssues in this report.

Source

pub fn infos_mut(&mut self) -> &mut [ValidationIssue]

Returns all informational ValidationIssues mutably.

Source

pub fn add_error(&mut self, issue: ValidationIssue)

Add an error to the report.

Source

pub fn add_warning(&mut self, issue: ValidationIssue)

Add a warning to the report.

Source

pub fn add_info(&mut self, issue: ValidationIssue)

Add an info message to the report.

Source

pub fn has_errors(&self) -> bool

Check if the report has any errors (Critical or Error severity).

Source

pub fn has_critical_errors(&self) -> bool

Check if the report contains at least one Critical-severity issue.

O(1) — backed by an incrementally maintained counter.

Source

pub fn has_warnings(&self) -> bool

Check if the report has any warnings.

Source

pub fn total_issues(&self) -> usize

Get the total count of all issues.

Source

pub fn is_valid(&self) -> bool

Check if the validation passed (no errors, but may have warnings).

Source

pub fn result(self) -> Result<ValidationReport, ValidationReport>

Convert to a Result.

Returns Ok(self) when there are no errors. Returns Err(self) when there is at least one error-level issue, preserving warnings and infos in the Err variant so callers can inspect the full report.

Source

pub fn iter_issues(&self) -> impl Iterator<Item = &ValidationIssue>

Iterate over all issues in severity buckets: errors, warnings, then infos.

Source

pub fn has_any_issues(&self) -> bool

Return true if the report contains any issues (errors, warnings, or infos).

Source

pub fn merge(&mut self, other: ValidationReport)

Drain all issues from other into self.

Issues are appended in severity order: errors, warnings, infos. other is left empty after this call.

Source

pub fn extend_from(&mut self, other: &ValidationReport)

Extend self with cloned issues from other (borrowing).

Unlike merge, this method borrows other so the caller retains ownership. Issues are cloned and appended to the respective severity buckets. Use merge when you can afford to consume other.

§Example
use edifact_rs::{ValidationReport, ValidationIssue, ValidationSeverity};

let mut combined = ValidationReport::default();
let report = ValidationReport::from_issues(
    vec![ValidationIssue::new(ValidationSeverity::Error, "bad segment")],
    vec![],
    vec![],
);
combined.extend_from(&report);
assert_eq!(combined.errors().len(), 1);
// `report` is still accessible
assert_eq!(report.errors().len(), 1);
Source

pub fn issues_for_rule_id<'a>( &'a self, rule_id: &'a str, ) -> impl Iterator<Item = &'a ValidationIssue> + 'a

Iterate over all issues matching an exact profile/MIG rule identifier.

Searches errors, warnings, and infos in that order. Returns a lazy iterator; collect into Vec if you need random access.

Source

pub fn filter_by_rule_id(&self, rule_id: &str) -> ValidationReport

Return a cloned report containing only issues with an exact rule identifier.

Source

pub fn filter_by_rule_prefix(&self, prefix: &str) -> ValidationReport

Return a cloned report containing only issues whose rule identifier starts with prefix.

Source

pub fn for_segment(&self, segment_tag: &str) -> ValidationReport

Return a cloned report containing only issues that reference segment_tag.

Issues whose segment_tag field does not match are dropped; the severity buckets (errors / warnings / infos) are preserved.

§Example
use edifact_rs::{ValidationReport, ValidationIssue, ValidationSeverity};

let mut report = ValidationReport::default();
report.add_error(
    ValidationIssue::new(ValidationSeverity::Error, "BGM missing")
        .with_segment("BGM"),
);
report.add_error(
    ValidationIssue::new(ValidationSeverity::Error, "NAD missing")
        .with_segment("NAD"),
);
let bgm_issues = report.for_segment("BGM");
assert_eq!(bgm_issues.errors().len(), 1);
assert_eq!(bgm_issues.errors()[0].segment_tag.as_deref(), Some("BGM"));
Source

pub fn render_deterministic(&self) -> String

Return a deterministic, stable text representation for snapshots and logs.

Trait Implementations§

Source§

impl Clone for ValidationReport

Source§

fn clone(&self) -> ValidationReport

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 ValidationReport

Source§

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

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

impl Default for ValidationReport

Source§

fn default() -> ValidationReport

Returns the “default value” for a type. Read more
Source§

impl Display for ValidationReport

Source§

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

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

impl Error for ValidationReport

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 Extend<ValidationIssue> for ValidationReport

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = ValidationIssue>,

Push each issue into the appropriate severity bucket.

This enables ergonomic batch collection:

use edifact_rs::{ValidationReport, ValidationIssue, ValidationSeverity};

let issues = vec![
    ValidationIssue::new(ValidationSeverity::Error, "bad segment"),
    ValidationIssue::new(ValidationSeverity::Warning, "optional field missing"),
    ValidationIssue::new(ValidationSeverity::Info, "advisory note"),
];
let mut report = ValidationReport::default();
report.extend(issues);
assert_eq!(report.errors().len(), 1);
assert_eq!(report.warnings().len(), 1);
assert_eq!(report.infos().len(), 1);
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<ValidationIssue> for ValidationReport

Source§

fn from_iter<I>(iter: I) -> ValidationReport
where I: IntoIterator<Item = ValidationIssue>,

Creates a value from an iterator. Read more
Source§

impl PartialEq for ValidationReport

Source§

fn eq(&self, other: &ValidationReport) -> 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 ValidationReport

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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, O> Matches<O> for T
where T: PartialEq<O>,

Source§

fn validate_matches(&self, other: &O) -> bool

Source§

impl<T> ToCompactString for T
where T: Display,

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.