mirror of https://github.com/rwf2/Rocket.git
Impl 'DerefMut' for 'Form', 'LenientForm'.
This commit is contained in:
parent
b18cd6460e
commit
080d586a35
|
@ -1,4 +1,4 @@
|
||||||
use std::ops::Deref;
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
use crate::outcome::Outcome::*;
|
use crate::outcome::Outcome::*;
|
||||||
use crate::request::{Request, form::{FromForm, FormItems, FormDataError}};
|
use crate::request::{Request, form::{FromForm, FormItems, FormDataError}};
|
||||||
|
@ -48,8 +48,8 @@ use crate::http::{Status, uri::{Query, FromUriParam}};
|
||||||
/// # fn main() { }
|
/// # fn main() { }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// A type of `Form<T>` automatically dereferences into an `&T`, though you can
|
/// A type of `Form<T>` automatically dereferences into an `&T` or `&mut T`,
|
||||||
/// also transform a `Form<T>` into a `T` by calling
|
/// though you can also transform a `Form<T>` into a `T` by calling
|
||||||
/// [`into_inner()`](Form::into_inner()). Thanks to automatic dereferencing, you
|
/// [`into_inner()`](Form::into_inner()). Thanks to automatic dereferencing, you
|
||||||
/// can access fields of `T` transparently through a `Form<T>`, as seen above
|
/// can access fields of `T` transparently through a `Form<T>`, as seen above
|
||||||
/// with `user_input.value`.
|
/// with `user_input.value`.
|
||||||
|
@ -146,6 +146,12 @@ impl<T> Deref for Form<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> DerefMut for Form<T> {
|
||||||
|
fn deref_mut(&mut self) -> &mut T {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'f, T: FromForm<'f>> Form<T> {
|
impl<'f, T: FromForm<'f>> Form<T> {
|
||||||
pub(crate) fn from_data(
|
pub(crate) fn from_data(
|
||||||
form_str: &'f str,
|
form_str: &'f str,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::ops::Deref;
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
use crate::request::{Request, form::{Form, FormDataError, FromForm}};
|
use crate::request::{Request, form::{Form, FormDataError, FromForm}};
|
||||||
use crate::data::{Data, Transformed, FromTransformedData, TransformFuture, FromDataFuture};
|
use crate::data::{Data, Transformed, FromTransformedData, TransformFuture, FromDataFuture};
|
||||||
|
@ -93,6 +93,12 @@ impl<T> Deref for LenientForm<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> DerefMut for LenientForm<T> {
|
||||||
|
fn deref_mut(&mut self) -> &mut T {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'r, T: FromForm<'r> + Send + 'r> FromTransformedData<'r> for LenientForm<T> {
|
impl<'r, T: FromForm<'r> + Send + 'r> FromTransformedData<'r> for LenientForm<T> {
|
||||||
type Error = FormDataError<'r, T::Error>;
|
type Error = FormDataError<'r, T::Error>;
|
||||||
type Owned = String;
|
type Owned = String;
|
||||||
|
|
Loading…
Reference in New Issue