Struct validatron::error::ErrorBuilder
source · [−]pub struct ErrorBuilder { /* private fields */ }
Expand description
A convenience type for building a structured error type
Implementations
sourceimpl ErrorBuilder
impl ErrorBuilder
sourcepub fn contains_errors(&self) -> bool
pub fn contains_errors(&self) -> bool
does the builder contain any error messages, used to short circuit various functions if no error has been detected.
sourcepub fn build(&mut self) -> Result<()>
pub fn build(&mut self) -> Result<()>
Consume the builder and produce a Result
let e = Error::build()
.at_named("a", "flat out broken")
.build();
assert!(e.is_err());
sourcepub fn at_location(
&mut self,
location: Location,
message: impl Into<Cow<'static, str>>
) -> &mut Self
pub fn at_location(
&mut self,
location: Location,
message: impl Into<Cow<'static, str>>
) -> &mut Self
extend the existing builder with an error at the specified location
sourcepub fn at_named(
&mut self,
name: impl Into<Cow<'static, str>>,
message: impl Into<Cow<'static, str>>
) -> &mut Self
pub fn at_named(
&mut self,
name: impl Into<Cow<'static, str>>,
message: impl Into<Cow<'static, str>>
) -> &mut Self
extend an existing builder with an error at a named location
let e = Error::build()
.at_named("field_1", "should be empty")
.build();
sourcepub fn at_index(
&mut self,
index: usize,
message: impl Into<Cow<'static, str>>
) -> &mut Self
pub fn at_index(
&mut self,
index: usize,
message: impl Into<Cow<'static, str>>
) -> &mut Self
extend an existing builder with an error at an indexed location
let e = Error::build()
.at_index(1, "value should be even")
.build();
sourcepub fn try_at_location(
&mut self,
location: Location,
result: Result<()>
) -> &mut Self
pub fn try_at_location(
&mut self,
location: Location,
result: Result<()>
) -> &mut Self
extend the existing builder at the specified location if the result is an error
let e = Error::build()
.try_at_location(Location::Index(1), Ok(()))
.build();
assert!(e.is_ok());
Auto Trait Implementations
impl RefUnwindSafe for ErrorBuilder
impl Send for ErrorBuilder
impl Sync for ErrorBuilder
impl Unpin for ErrorBuilder
impl UnwindSafe for ErrorBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more