pub struct Errors { /* private fields */ }Expand description
The messages a failed validation produced, grouped by field.
wants_json is captured when the errors are built from a request, because
IntoResponse::into_response no longer has the request to negotiate with.
Implementations§
Source§impl Errors
impl Errors
pub fn new() -> Self
pub fn add(&mut self, field: impl Into<String>, message: impl Into<String>)
pub fn has(&self, field: &str) -> bool
Sourcepub fn first(&self, field: &str) -> Option<&str>
pub fn first(&self, field: &str) -> Option<&str>
The first message for a field — what a form renders next to the input.
Sourcepub fn all(&self) -> &BTreeMap<String, Vec<String>>
pub fn all(&self) -> &BTreeMap<String, Vec<String>>
Every message for every field, keyed by field name.
pub fn is_empty(&self) -> bool
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The number of messages, not the number of fields — one field can fail several rules.
pub fn fields(&self) -> impl Iterator<Item = &str>
Sourcepub fn wants_json(&self) -> bool
pub fn wants_json(&self) -> bool
Whether the response should be JSON. Set from Request::wants_json.
pub fn with_json(self, wants_json: bool) -> Self
Sourcepub fn with(self, field: impl Into<String>, message: impl Into<String>) -> Self
pub fn with(self, field: impl Into<String>, message: impl Into<String>) -> Self
Add a message by hand, chaining — useful for a rule an application enforces itself, so its failure comes back in the same envelope as the built-in ones.
Sourcepub fn add_interpolated(
&mut self,
messages: &Messages,
field: &str,
template: &str,
)
pub fn add_interpolated( &mut self, messages: &Messages, field: &str, template: &str, )
Render a hand-written message through the message bag’s label rules, so
it interpolates :attribute the way a built-in one does.
Trait Implementations§
Source§impl Error for Errors
impl Error for Errors
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl IntoResponse for Errors
A 422, as JSON for an API client and as plain text for a browser.
impl IntoResponse for Errors
A 422, as JSON for an API client and as plain text for a browser.
The HTML side is intentionally minimal for now: re-rendering the submitted form with the messages attached needs the view layer, which is a later phase.