From 080d586a356b7ffc3617b98ecbc57457f1d9acaa Mon Sep 17 00:00:00 2001 From: ThouCheese Date: Sat, 10 Oct 2020 10:37:16 +0200 Subject: [PATCH] Impl 'DerefMut' for 'Form', 'LenientForm'. --- core/lib/src/request/form/form.rs | 12 +++++++++--- core/lib/src/request/form/lenient.rs | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) 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;