pub struct ValidationError {
pub type_name: &'static str,
pub reason: String,
}Expand description
A validation failure for a domain value, naming the type that rejected the value and why.
type_name is a plain string, not tied to Self by the compiler: it is
whatever the caller of ValidationError::new passes in. Derive-macro
generated code always passes the exact type name it was expanded for, so
it is guaranteed accurate there. A hand-written impl (as in this
crate’s own test fixtures) must keep the type_name argument in sync
with the type by hand - copy-pasting an impl from one type to another is
the most likely way for it to drift.
§Examples
use ddd_toolkit_core::domain::ValidationError;
let error = ValidationError::new("Email", "missing '@'");
assert_eq!(error.type_name, "Email");
assert_eq!(error.reason, "missing '@'");
assert_eq!(error.to_string(), "invalid Email: missing '@'");Fields§
§type_name: &'static strThe name of the type that rejected the value.
reason: StringA human-readable explanation of why the value was rejected.
Implementations§
Trait Implementations§
Source§impl Clone for ValidationError
impl Clone for ValidationError
Source§fn clone(&self) -> ValidationError
fn clone(&self) -> ValidationError
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ValidationError
impl Debug for ValidationError
Source§impl Display for ValidationError
impl Display for ValidationError
impl Eq for ValidationError
Source§impl Error for ValidationError
impl Error for ValidationError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl PartialEq for ValidationError
impl PartialEq for ValidationError
impl StructuralPartialEq for ValidationError
Auto Trait Implementations§
impl Freeze for ValidationError
impl RefUnwindSafe for ValidationError
impl Send for ValidationError
impl Sync for ValidationError
impl Unpin for ValidationError
impl UnsafeUnpin for ValidationError
impl UnwindSafe for ValidationError
Blanket Implementations§
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
Mutably borrows from an owned value. Read more