pub struct Error {
pub kind: ErrorKind,
pub path: Vec<Segment>,
pub location: Option<Box<Location>>,
pub meta: Option<Box<Meta>>,
}Expand description
Fields§
§kind: ErrorKind§path: Vec<Segment>Path from the validated root to the offending value (root-first).
location: Option<Box<Location>>Source location, filled in by the enclosing value that owns it.
Boxed to keep Error small enough to return by value (clippy::result_large_err).
meta: Option<Box<Meta>>The failing validator’s human-facing metadata (name/description/examples/default).
Boxed for the same size reason as location; filled in by the validator that failed
(innermost wins).
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(kind: ErrorKind) -> Self
pub fn new(kind: ErrorKind) -> Self
Build a path-less, location-less error for the value currently being validated.
Sourcepub fn with_location(self, location: &Location) -> Self
pub fn with_location(self, location: &Location) -> Self
Attach location unless one is already set (the innermost owner wins).
Sourcepub fn with_meta(self, meta: &Meta) -> Self
pub fn with_meta(self, meta: &Meta) -> Self
Attach the failing validator’s Meta unless one is already set (innermost wins).
Sourcepub fn default_value(&self) -> Option<&Value>
pub fn default_value(&self) -> Option<&Value>
The failing validator’s default value, if it declared one.
Sourcepub fn under_key(self, key: &str, location: &Location) -> Self
pub fn under_key(self, key: &str, location: &Location) -> Self
Record that this error happened under map key key, whose value lives at location.
Sourcepub fn under_index(self, index: usize, location: &Location) -> Self
pub fn under_index(self, index: usize, location: &Location) -> Self
Record that this error happened under list index index, whose item lives at location.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()