#[derive(FromForm)]
{
// Attributes available to this derive:
#[form]
}
Expand description
Automatically derive FromForm from a struct.
Note that this requires a struct - as x-www-form-urlencoded is a
key-value format, there is no way to derive FromForm for a tuple or enum.
Thus, there must be keys. However, for tuple structs, the keys can be
specified with the form attribute.
The form attribute currently accepts these parameters:
rename_all = "value"- this may only be specified on the whole struct. If it is specified, the given transformation is applied to all field names, if they are not individually renamed. Valid values are"snake_case","camelCase","PascalCase","SCREAMING_SNAKE_CASE","kebab-case","SCREAMING-KEBAB-CASE","lowercase", and"uppercase".rename = "value"- this may only be specified on a field. If it is specified, the given name is used instead of the field name. This is useful for when the field name is not a valid identifier, or when the field name is not the same as the key in the form.alias = "value"- this may only be specified on a field. If it is specified, the given name is used as an alias for the field. This is in addition to, not instead of, the field name; if you want instead of, userename. This can be specified multiple times to add multiple aliases.default- this may only be specified on a field. If it is specified, the field is optional; if it is not present in the form, the default value is used (throughDefault::default).default = "value"- similar to above, but it uses the function specified byvalue(as a path) to get the default value. This is incompatible withoptionalandmultiple.optional- this may only be specified on a field. If it is specified, the field is optional; if it is not present in the form, the field is skipped. It is expected that the type of this field isOption<T>. This is different fromdefaultin how the field is handled:defaultwill use the default value of the type, whileoptionalwill skip the field entirely. This is incompatible withdefaultandmultiple.multiple- this may only be specified on a field. If it is specified, the field is a multiple field; it is expected that the type of this field implementsFromFieldMultipleinstead ofFromFieldValue. It pushes the inner value every time the key is encountered. This is incompatible withdefaultandoptional.parse_with = "value"- this may only be specified on a field. If it is specified, the field is parsed with the given function. The function must be a path to a function that takes a&strand returns aResult<T, E>, whereTis the type of the field andEis the error type.