pub trait FormRequest:
DeserializeOwned
+ Send
+ Sync
+ 'static {
// Required method
fn rules() -> RuleSet;
// Provided methods
fn authorize<'life0, 'async_trait>(
request: &'life0 Request,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait { ... }
fn messages() -> Vec<(&'static str, &'static str)> { ... }
fn validation_data(request: &Request) -> Value { ... }
fn from_input(input: Value) -> Result<Self> { ... }
fn validate_request<'life0, 'async_trait>(
request: &'life0 Request,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn validator() -> Validator { ... }
fn check(request: &Request) -> Result<(), ValidationErrors> { ... }
}Expand description
A typed, authorised, validated request payload.
Required Methods§
Provided Methods§
Whether the caller may make this request at all.
Runs before validation, so an unauthorised caller cannot use
validation messages to probe what the endpoint expects. Returning
false produces a 403.
async because a real authorisation check reads a policy, a role, or
the record being modified.
Sourcefn messages() -> Vec<(&'static str, &'static str)>
fn messages() -> Vec<(&'static str, &'static str)>
Messages overriding the defaults, keyed "field.rule".
Sourcefn validation_data(request: &Request) -> Value
fn validation_data(request: &Request) -> Value
What to validate. Defaults to the merged query string and body.
Override to fold in route parameters — an update contract that needs
{post} to check uniqueness-except-self, for instance.
Sourcefn from_input(input: Value) -> Result<Self>
fn from_input(input: Value) -> Result<Self>
Build the payload from the validated input.
The default deserialises with string coercion, so a urlencoded form
fills a u32 field. Override for a payload that is not a plain
deserialisation of the input.
Sourcefn validate_request<'life0, 'async_trait>(
request: &'life0 Request,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn validate_request<'life0, 'async_trait>(
request: &'life0 Request,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run authorisation and validation, and build the payload.
The whole contract in one call, so it can be used outside an extractor — from a console command, or a test.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".