pub trait FormValidate: Sized {
// Required methods
fn validate<'life0, 'async_trait>(
data: &'life0 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<Self, ValidationErrors>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn fields() -> Vec<Field>;
// Provided method
fn render_html<'life0, 'async_trait>(
data: &'life0 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait { ... }
}Expand description
The contract a typed form satisfies. validate reads form data
(a HashMap<String, String>, the natural shape after
serde_urlencoded or axum’s Form extractor) and produces either
the typed struct or a ValidationErrors map describing every
problem at once.
render_html writes the form’s HTML inputs, prefilled from a
HashMap on the re-render path (after a validation failure or on
edit views). The default impl walks fields() and concatenates
each field’s render_html — most macro-derived forms inherit
this and only override when they need custom layout.
Required Methods§
Sourcefn validate<'life0, 'async_trait>(
data: &'life0 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<Self, ValidationErrors>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn validate<'life0, 'async_trait>(
data: &'life0 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<Self, ValidationErrors>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Parse and validate the form’s input. Async because FK / M2M
fields verify existence through the ORM before insert. Returns
the typed struct on success; returns ValidationErrors with
every field’s problems accumulated on failure.
Provided Methods§
Sourcefn render_html<'life0, 'async_trait>(
data: &'life0 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
fn render_html<'life0, 'async_trait>(
data: &'life0 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
Render every field as an HTML <label> + <input> pair,
prefilled from data. Wraps each in a <div class="field">
for styling. Async because ModelChoice / ModelMultiChoice
fetch their <select> options from the DB. Override if you
want a non-default layout.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".