pub enum FieldError {
Required(String),
Invalid(String),
Validation(String),
}Variants§
Implementations§
Source§impl FieldError
impl FieldError
Sourcepub fn required(custom_msg: Option<&str>) -> Self
pub fn required(custom_msg: Option<&str>) -> Self
Creates a required field error
§Examples
use reinhardt_forms::FieldError;
let error = FieldError::required(None);
assert_eq!(error.to_string(), "This field is required.");
let custom_error = FieldError::required(Some("Name is mandatory"));
assert_eq!(custom_error.to_string(), "Name is mandatory");Sourcepub fn invalid(custom_msg: Option<&str>, default_msg: &str) -> Self
pub fn invalid(custom_msg: Option<&str>, default_msg: &str) -> Self
Creates an invalid field error
§Examples
use reinhardt_forms::FieldError;
let error = FieldError::invalid(None, "Invalid input format");
assert_eq!(error.to_string(), "Invalid input format");
let custom_error = FieldError::invalid(Some("Must be a number"), "Invalid");
assert_eq!(custom_error.to_string(), "Must be a number");Sourcepub fn validation(custom_msg: Option<&str>, default_msg: &str) -> Self
pub fn validation(custom_msg: Option<&str>, default_msg: &str) -> Self
Creates a validation field error
§Examples
use reinhardt_forms::FieldError;
let error = FieldError::validation(None, "Value out of range");
assert_eq!(error.to_string(), "Value out of range");
let custom_error = FieldError::validation(Some("Too long"), "Length exceeded");
assert_eq!(custom_error.to_string(), "Too long");Trait Implementations§
Source§impl Debug for FieldError
impl Debug for FieldError
Source§impl Display for FieldError
impl Display for FieldError
Source§impl Error for FieldError
impl Error for FieldError
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()
Auto Trait Implementations§
impl Freeze for FieldError
impl RefUnwindSafe for FieldError
impl Send for FieldError
impl Sync for FieldError
impl Unpin for FieldError
impl UnsafeUnpin for FieldError
impl UnwindSafe for FieldError
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