mirror of https://github.com/rwf2/Rocket.git
Implement 'FromForm' for 'Option' and 'Result'.
This commit is contained in:
parent
02f466fa17
commit
82a2d2f44e
|
@ -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<T: FromForm>`, `Result<T: FromForm,
|
||||
T::Error>`.
|
||||
|
||||
[Fairings]: #FIXME
|
||||
[Native TLS support]: #FIXME
|
||||
|
|
|
@ -124,3 +124,21 @@ impl<'f> FromForm<'f> for &'f 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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue