Impl 'DerefMut' for 'Form', 'LenientForm'.

This commit is contained in:
ThouCheese 2020-10-10 10:37:16 +02:00 committed by Sergio Benitez
parent b18cd6460e
commit 080d586a35
2 changed files with 16 additions and 4 deletions

View File

@ -1,4 +1,4 @@
use std::ops::Deref;
use std::ops::{Deref, DerefMut};
use crate::outcome::Outcome::*;
use crate::request::{Request, form::{FromForm, FormItems, FormDataError}};
@ -48,8 +48,8 @@ use crate::http::{Status, uri::{Query, FromUriParam}};
/// # fn main() { }
/// ```
///
/// A type of `Form<T>` automatically dereferences into an `&T`, though you can
/// also transform a `Form<T>` into a `T` by calling
/// A type of `Form<T>` automatically dereferences into an `&T` or `&mut T`,
/// though you can also transform a `Form<T>` into a `T` by calling
/// [`into_inner()`](Form::into_inner()). Thanks to automatic dereferencing, you
/// can access fields of `T` transparently through a `Form<T>`, as seen above
/// 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> {
pub(crate) fn from_data(
form_str: &'f str,

View File

@ -1,4 +1,4 @@
use std::ops::Deref;
use std::ops::{Deref, DerefMut};
use crate::request::{Request, form::{Form, FormDataError, FromForm}};
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> {
type Error = FormDataError<'r, T::Error>;
type Owned = String;