pub struct ValidationContext { /* private fields */ }Expand description
Collects all validation diagnostics emitted during the loading pipeline.
Pass a &mut ValidationContext to each validation function. After all layers
have run, call into_result to convert the collected diagnostics into a
Result<(), LoadError>.
§Examples
use cobre_io::validation::{ValidationContext, ErrorKind};
let mut ctx = ValidationContext::new();
assert!(!ctx.has_errors());
assert!(ctx.into_result().is_ok());Implementations§
Source§impl ValidationContext
impl ValidationContext
Sourcepub fn add_error(
&mut self,
kind: ErrorKind,
file: impl Into<PathBuf>,
entity: Option<impl Into<String>>,
message: impl Into<String>,
)
pub fn add_error( &mut self, kind: ErrorKind, file: impl Into<PathBuf>, entity: Option<impl Into<String>>, message: impl Into<String>, )
Adds an error diagnostic to the context.
Sourcepub fn add_warning(
&mut self,
kind: ErrorKind,
file: impl Into<PathBuf>,
entity: Option<impl Into<String>>,
message: impl Into<String>,
)
pub fn add_warning( &mut self, kind: ErrorKind, file: impl Into<PathBuf>, entity: Option<impl Into<String>>, message: impl Into<String>, )
Adds a warning diagnostic to the context.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Returns true if any error-severity diagnostics have been collected.
Sourcepub fn error_count(&self) -> usize
pub fn error_count(&self) -> usize
Returns the number of error-severity diagnostics without allocating.
Sourcepub fn errors(&self) -> Vec<&ValidationEntry>
pub fn errors(&self) -> Vec<&ValidationEntry>
Returns all error-severity ValidationEntry items.
Sourcepub fn warnings(&self) -> Vec<&ValidationEntry>
pub fn warnings(&self) -> Vec<&ValidationEntry>
Returns a slice of all warning-severity ValidationEntry items.
Sourcepub fn into_result(self) -> Result<(), LoadError>
pub fn into_result(self) -> Result<(), LoadError>
Converts the collected diagnostics into a Result.
Warnings are not surfaced by this method — inspect warnings() before
calling into_result().
§Errors
Returns LoadError::ConstraintError if any error-severity diagnostics
were collected. The description field contains all error messages
joined by newlines, formatted as [ErrorKind] file (entity): message.
§Examples
use cobre_io::validation::{ValidationContext, ErrorKind};
let mut ctx = ValidationContext::new();
ctx.add_warning(ErrorKind::UnusedEntity, "system/thermals.json", Some("T1"), "inactive");
assert!(ctx.into_result().is_ok());Trait Implementations§
Source§impl Debug for ValidationContext
impl Debug for ValidationContext
Source§impl Default for ValidationContext
impl Default for ValidationContext
Source§fn default() -> ValidationContext
fn default() -> ValidationContext
Auto Trait Implementations§
impl Freeze for ValidationContext
impl RefUnwindSafe for ValidationContext
impl Send for ValidationContext
impl Sync for ValidationContext
impl Unpin for ValidationContext
impl UnsafeUnpin for ValidationContext
impl UnwindSafe for ValidationContext
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more