pub struct ValidationError {
pub path: FieldPath,
pub code: String,
pub message: String,
pub params: BTreeMap<String, ErrorParam>,
}Expand description
A single validation error with path, code, and message.
§Example
use skp_validator_core::{ValidationError, FieldPath};
let error = ValidationError::new("email", "email.invalid", "Must be a valid email address")
.with_param("value", "invalid-email");Fields§
§path: FieldPathPath to the field that failed validation
code: StringError code for programmatic handling (e.g., “email.invalid”, “length.min”)
message: StringHuman-readable error message
params: BTreeMap<String, ErrorParam>Additional parameters for error formatting and i18n
Implementations§
Source§impl ValidationError
impl ValidationError
Sourcepub fn new(
field: impl Into<String>,
code: impl Into<String>,
message: impl Into<String>,
) -> ValidationError
pub fn new( field: impl Into<String>, code: impl Into<String>, message: impl Into<String>, ) -> ValidationError
Create a new validation error.
§Arguments
field- The field name (will be converted to a FieldPath)code- Error code for programmatic handlingmessage- Human-readable message
Sourcepub fn with_path(
path: FieldPath,
code: impl Into<String>,
message: impl Into<String>,
) -> ValidationError
pub fn with_path( path: FieldPath, code: impl Into<String>, message: impl Into<String>, ) -> ValidationError
Create a new validation error with a full path.
Sourcepub fn root(
code: impl Into<String>,
message: impl Into<String>,
) -> ValidationError
pub fn root( code: impl Into<String>, message: impl Into<String>, ) -> ValidationError
Create a root-level error (empty path).
Sourcepub fn with_param(
self,
key: impl Into<String>,
value: impl Into<ErrorParam>,
) -> ValidationError
pub fn with_param( self, key: impl Into<String>, value: impl Into<ErrorParam>, ) -> ValidationError
Add a parameter to this error.
Sourcepub fn field_name(&self) -> Option<&str>
pub fn field_name(&self) -> Option<&str>
Get the field name (last segment of path)
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 · 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<'de> Deserialize<'de> for ValidationError
impl<'de> Deserialize<'de> for ValidationError
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ValidationError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ValidationError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for ValidationError
impl Display 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 FromIterator<ValidationError> for ValidationErrors
impl FromIterator<ValidationError> for ValidationErrors
Source§fn from_iter<I>(iter: I) -> ValidationErrorswhere
I: IntoIterator<Item = ValidationError>,
fn from_iter<I>(iter: I) -> ValidationErrorswhere
I: IntoIterator<Item = ValidationError>,
Creates a value from an iterator. Read more
Source§impl Serialize for ValidationError
impl Serialize for ValidationError
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for ValidationError
impl RefUnwindSafe for ValidationError
impl Send for ValidationError
impl Sync for ValidationError
impl Unpin 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