pub struct FormErrors(/* private fields */);Available on crate feature
alloc only.Expand description
Every problem with one submitted form, for showing the form again with
a message beside each field: what
FromForm::from_body_all returns.
A parse error (a malformed body, a limit) stops the parse, so it is the only error; extraction errors are collected for every field, at most one per received value plus one per missing field. No value is ever kept.
§Examples
use form_net::{ExtractError, FromForm};
form_net::form! {
#[derive(Debug)]
pub struct Signup { pub email: String, pub age: u8, pub tos: bool }
}
let errors = Signup::from_body_all(b"application/x-www-form-urlencoded", b"age=300&role=admin").unwrap_err();
assert_eq!(errors.len(), 3);
assert_eq!(errors.field("age"), Some(ExtractError::Invalid("out of range")));
assert_eq!(errors.field("email"), Some(ExtractError::Missing));
assert_eq!(errors.unknown(), 1);
assert_eq!(errors.status_hint(), 422);Implementations§
Source§impl FormErrors
impl FormErrors
Sourcepub fn field(&self, name: &str) -> Option<ExtractError>
pub fn field(&self, name: &str) -> Option<ExtractError>
The first extraction error for the field with this Rust name.
Sourcepub fn unknown(&self) -> usize
pub fn unknown(&self) -> usize
How many received names the struct neither declares nor ignores.
Sourcepub fn status_hint(&self) -> u16
pub fn status_hint(&self) -> u16
The status hint of the first error (422 for extraction errors).
Trait Implementations§
Source§impl Clone for FormErrors
impl Clone for FormErrors
Source§impl Debug for FormErrors
impl Debug for FormErrors
Source§impl Display for FormErrors
impl Display for FormErrors
impl Eq for FormErrors
Source§impl Error for FormErrors
Available on crate feature std only.
impl Error for FormErrors
Available on crate feature
std only.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 From<FormError> for FormErrors
impl From<FormError> for FormErrors
Source§fn from(e: FormError) -> FormErrors
fn from(e: FormError) -> FormErrors
Converts to this type from the input type.
Source§impl PartialEq for FormErrors
impl PartialEq for FormErrors
impl StructuralPartialEq for FormErrors
Auto Trait Implementations§
impl Freeze for FormErrors
impl RefUnwindSafe for FormErrors
impl Send for FormErrors
impl Sync for FormErrors
impl Unpin for FormErrors
impl UnsafeUnpin for FormErrors
impl UnwindSafe for FormErrors
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