Implement 'FromForm' for 'Option' and 'Result'.

This commit is contained in:
Sergio Benitez 2017-07-03 02:13:35 -07:00
parent 02f466fa17
commit 82a2d2f44e
2 changed files with 20 additions and 0 deletions

View File

@ -46,6 +46,8 @@ This release includes the following new features:
* Quoted string, array, and table based [configuration parameters] can be set * Quoted string, array, and table based [configuration parameters] can be set
via environment variables. via environment variables.
* Log coloring is disabled when `stdout` is not a TTY. * Log coloring is disabled when `stdout` is not a TTY.
* [`FromForm`] is implemented for `Option<T: FromForm>`, `Result<T: FromForm,
T::Error>`.
[Fairings]: #FIXME [Fairings]: #FIXME
[Native TLS support]: #FIXME [Native TLS support]: #FIXME

View File

@ -124,3 +124,21 @@ impl<'f> FromForm<'f> for &'f str {
Ok(items.inner_str()) Ok(items.inner_str())
} }
} }
impl<'f, T: FromForm<'f>> FromForm<'f> for Option<T> {
type Error = !;
#[inline]
fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result<Option<T>, !> {
Ok(T::from_form(items, strict).ok())
}
}
impl<'f, T: FromForm<'f>> FromForm<'f> for Result<T, T::Error> {
type Error = !;
#[inline]
fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result<Self, !> {
Ok(T::from_form(items, strict))
}
}