Skip to content

Commit

Permalink
Document that '&[u8]' is a form guard.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed Oct 2, 2023
1 parent 5d31ad4 commit 47faac6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/lib/src/form/from_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]`) |
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 22 additions & 1 deletion core/lib/src/form/from_form_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 47faac6

Please sign in to comment.