Document that '&[u8]' is a form guard.

This commit is contained in:
Sergio Benitez 2023-10-02 11:59:03 -07:00
parent ed56056d0e
commit a20f9d8e89
2 changed files with 25 additions and 2 deletions

View File

@ -120,7 +120,7 @@ use crate::http::uncased::AsUncased;
/// | IP Address | _inherit_ | **no default** | No | Yes | [`IpAddr`], [`Ipv4Addr`], [`Ipv6Addr`] |
/// | Socket Address | _inherit_ | **no default** | No | Yes | [`SocketAddr`], [`SocketAddrV4`], [`SocketAddrV6`] |
/// | [`TempFile`] | _inherit_ | **no default** | Yes | Yes | Data limits apply. See [`TempFile`]. |
/// | [`Capped<C>`] | _inherit_ | **no default** | Yes | Yes | `C` is `&str`, `String`, or `TempFile`. |
/// | [`Capped<C>`] | _inherit_ | **no default** | Yes | Yes | `C` is `&str`, `String`, `&[u8]` or `TempFile`. |
/// | [`time::Date`] | _inherit_ | **no default** | No | Yes | `%F` (`YYYY-MM-DD`). HTML "date" input. |
/// | [`time::DateTime`] | _inherit_ | **no default** | No | Yes | `%FT%R` or `%FT%T` (`YYYY-MM-DDTHH:MM[:SS]`) |
/// | [`time::Time`] | _inherit_ | **no default** | No | Yes | `%R` or `%T` (`HH:MM[:SS]`) |
@ -628,6 +628,8 @@ impl<'v, T: FromForm<'v> + 'v> FromForm<'v> for Vec<T> {
}
}
// impl_strict_from_form_field_from_capped!(Vec<u8>);
#[doc(hidden)]
pub struct MapContext<'v, K, V> where K: FromForm<'v>, V: FromForm<'v> {
opts: Options,

View File

@ -28,11 +28,32 @@ use crate::form::prelude::*;
/// }
/// ```
///
/// # Semantics
///
/// The implementation of `FromForm` for a `T: FromFormField` type operates as
/// follows:
///
/// * When parsing is **strict**, the parser accepts the _first_ value or data
/// field with the corresponding field name and calls `T::from_value()` or
/// `T::from_data()` with the field's value, respectively. If more than one
/// field value is seen, an [`ErrorKind::Duplicate`) is emitted. If no
/// matching field is seen, an [`ErrorKind::Missing`] is emitted. Otherwise,
/// the result from the call is emitted.
///
/// * When parsing is **lenient**, the parser accepts the first _expected_
/// value or data field with the corresponding field name and calls
/// `T::from_value()` or `T::from_data()` with the field's value,
/// respectively. Unexpected values, identified by returning an
/// [`ErrorKind::Unexpected`] from `from_value()` or `from_data()` are
/// ignored. Any additional fields with a matching field name are ignored.
/// If no matching field is seen and `T` has a default, it is used,
/// otherwise an [`ErrorKind::Missing`] is emitted.
///
/// # Deriving
///
/// `FromFormField` can be derived for C-like enums, where the generated
/// implementation case-insensitively parses fields with values equal to the
/// name of the variant or the value in `field(value = "...")`.
/// name of the variant or the value in `field()`.
///
/// ```rust
/// # use rocket::form::FromFormField;