From 82a2d2f44ea16416fc9a52f0a96eac166748b08f Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 3 Jul 2017 02:13:35 -0700 Subject: [PATCH] Implement 'FromForm' for 'Option' and 'Result'. --- CHANGELOG.md | 2 ++ lib/src/request/form/from_form.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bd43924..39b62306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ This release includes the following new features: * Quoted string, array, and table based [configuration parameters] can be set via environment variables. * Log coloring is disabled when `stdout` is not a TTY. + * [`FromForm`] is implemented for `Option`, `Result`. [Fairings]: #FIXME [Native TLS support]: #FIXME diff --git a/lib/src/request/form/from_form.rs b/lib/src/request/form/from_form.rs index 7b57b788..864d55db 100644 --- a/lib/src/request/form/from_form.rs +++ b/lib/src/request/form/from_form.rs @@ -124,3 +124,21 @@ impl<'f> FromForm<'f> for &'f str { Ok(items.inner_str()) } } + +impl<'f, T: FromForm<'f>> FromForm<'f> for Option { + type Error = !; + + #[inline] + fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result, !> { + Ok(T::from_form(items, strict).ok()) + } +} + +impl<'f, T: FromForm<'f>> FromForm<'f> for Result { + type Error = !; + + #[inline] + fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result { + Ok(T::from_form(items, strict)) + } +}