diff --git a/core/lib/src/request/form/form.rs b/core/lib/src/request/form/form.rs index 63d221e7..5b91e648 100644 --- a/core/lib/src/request/form/form.rs +++ b/core/lib/src/request/form/form.rs @@ -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` automatically dereferences into an `&T`, though you can -/// also transform a `Form` into a `T` by calling +/// A type of `Form` automatically dereferences into an `&T` or `&mut T`, +/// though you can also transform a `Form` into a `T` by calling /// [`into_inner()`](Form::into_inner()). Thanks to automatic dereferencing, you /// can access fields of `T` transparently through a `Form`, as seen above /// with `user_input.value`. @@ -146,6 +146,12 @@ impl Deref for Form { } } +impl DerefMut for Form { + fn deref_mut(&mut self) -> &mut T { + &mut self.0 + } +} + impl<'f, T: FromForm<'f>> Form { pub(crate) fn from_data( form_str: &'f str, diff --git a/core/lib/src/request/form/lenient.rs b/core/lib/src/request/form/lenient.rs index 29b10225..04e49c10 100644 --- a/core/lib/src/request/form/lenient.rs +++ b/core/lib/src/request/form/lenient.rs @@ -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 Deref for LenientForm { } } +impl DerefMut for LenientForm { + fn deref_mut(&mut self) -> &mut T { + &mut self.0 + } +} + impl<'r, T: FromForm<'r> + Send + 'r> FromTransformedData<'r> for LenientForm { type Error = FormDataError<'r, T::Error>; type Owned = String;