pub struct Input { /* private fields */ }Expand description
The named values under validation.
Implementations§
Source§impl Input
impl Input
pub fn new() -> Self
Sourcepub fn from_json(value: &Json) -> Self
pub fn from_json(value: &Json) -> Self
Take the top level of a JSON object.
A body that is not an object — an array, a bare string — has no named
fields, so it validates as empty and required rules report what is
missing. That is a better failure than a parse error the client cannot act on.
Sourcepub fn from_pairs<K: AsRef<str>, V: AsRef<str>>(
pairs: impl IntoIterator<Item = (K, V)>,
) -> Self
pub fn from_pairs<K: AsRef<str>, V: AsRef<str>>( pairs: impl IntoIterator<Item = (K, V)>, ) -> Self
Build from name/value pairs — a form body or a query string.
A repeated key becomes an array, because that is how a browser sends a
group of checkboxes, and it is what makes array and a counting min
work on one.
Sourcepub fn from_request(request: &mut Request) -> Self
pub fn from_request(request: &mut Request) -> Self
Everything a request carries, in Request::input’s precedence order:
the query string first, then a form body, then a JSON body on top.
Sourcepub fn merge(&mut self, other: Input)
pub fn merge(&mut self, other: Input)
Overlay another set of values, replacing any field they share.
pub fn insert(&mut self, name: impl Into<String>, value: impl Into<Json>)
Sourcepub fn with(self, name: impl Into<String>, value: impl Into<Json>) -> Self
pub fn with(self, name: impl Into<String>, value: impl Into<Json>) -> Self
The chaining form of Input::insert, for building an input in a test
or from values the application already holds.
pub fn get(&self, name: &str) -> Option<&Json>
Sourcepub fn has(&self, name: &str) -> bool
pub fn has(&self, name: &str) -> bool
Whether the field was sent at all. A field sent as null is present.