pub enum ValidationError {
Schema {
code: &'static str,
message: Option<String>,
location: String,
},
Field {
field: Option<&'static str>,
code: &'static str,
params: Box<HashMap<&'static str, Value>>,
message: Option<String>,
location: String,
},
}Variants§
Schema
Fields
Field
Implementations§
Source§impl ValidationError
impl ValidationError
Sourcepub fn new_field(code: &'static str) -> ValidationError
pub fn new_field(code: &'static str) -> ValidationError
Creates a new field validation error. This should be used when returning errors from reusable custom functions as validify will automatically set field names.
Sourcepub fn new_field_named(
field: &'static str,
code: &'static str,
) -> ValidationError
pub fn new_field_named( field: &'static str, code: &'static str, ) -> ValidationError
Creates a new field error with the given field name and code.
Sourcepub fn new_schema(code: &'static str) -> ValidationError
pub fn new_schema(code: &'static str) -> ValidationError
Creates a new schema error with the given code
Sourcepub fn set_field(&mut self, field: &'static str)
pub fn set_field(&mut self, field: &'static str)
Set the field name to the given one if the error is a field error
Sourcepub fn field_name(&self) -> Option<&str>
pub fn field_name(&self) -> Option<&str>
Get the error’s field name if it was a field error
pub fn add_param<T: Serialize>(&mut self, name: &'static str, val: &T)
pub fn with_param<T: Serialize>(self, name: &'static str, val: &T) -> Self
pub fn with_message(self, msg: String) -> Self
Sourcepub fn set_location<T>(&mut self, parent: T)where
T: Display,
pub fn set_location<T>(&mut self, parent: T)where
T: Display,
Insert the provided parent to the 0th position of the current location
Sourcepub fn append_location<T>(&mut self, child: T)where
T: Display,
pub fn append_location<T>(&mut self, child: T)where
T: Display,
Append the provided parent to the current location
Sourcepub fn set_location_idx<T: Display>(&mut self, idx: T, parent: &str)
pub fn set_location_idx<T: Display>(&mut self, idx: T, parent: &str)
Used when the struct failing validation is nested in collections. It will concat the index to the parent so as to follow the location.
Sourcepub fn location(&self) -> &str
pub fn location(&self) -> &str
Returns the absolute location of the error in a similiar manner to JSON pointers.
pub fn params(&self) -> HashMap<&'static str, Value>
pub fn code(&self) -> String
pub fn message(&self) -> Option<String>
pub fn set_message(&mut self, msg: String)
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 Deserialize<'static> for ValidationError
impl Deserialize<'static> for ValidationError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'static>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'static>,
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
Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§impl PartialEq for ValidationError
impl PartialEq for ValidationError
Source§impl Serialize for ValidationError
impl Serialize for ValidationError
impl Eq 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 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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>
Converts
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>
Converts
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