From dd0c036461524c8a8a74a018af312eea56afae9e Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 16 Apr 2021 01:51:31 -0700 Subject: [PATCH] Allow 'T: Deserialize' in JSON, MessagePack forms. Previously, 'T: DeserializeOwned' was required needlessly. This allowed 'Json' and 'MsgPack' to borrow from the request. --- contrib/lib/src/json.rs | 5 ++--- contrib/lib/src/msgpack.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/contrib/lib/src/json.rs b/contrib/lib/src/json.rs index d533ca70..410b79d3 100644 --- a/contrib/lib/src/json.rs +++ b/contrib/lib/src/json.rs @@ -24,8 +24,7 @@ use rocket::response::{self, Responder, content}; use rocket::http::Status; use rocket::form::prelude as form; -use serde::{Serialize, Serializer}; -use serde::de::{Deserialize, DeserializeOwned, Deserializer}; +use serde::{Serialize, Serializer, Deserialize, Deserializer}; #[doc(hidden)] pub use serde_json::{json_internal, json_internal_vec}; @@ -237,7 +236,7 @@ impl From> for form::Error<'_> { } #[rocket::async_trait] -impl<'v, T: DeserializeOwned + Send> form::FromFormField<'v> for Json { +impl<'v, T: Deserialize<'v> + Send> form::FromFormField<'v> for Json { fn from_value(field: form::ValueField<'v>) -> Result> { Ok(Self::from_str(field.value)?) } diff --git a/contrib/lib/src/msgpack.rs b/contrib/lib/src/msgpack.rs index 60f28406..573245aa 100644 --- a/contrib/lib/src/msgpack.rs +++ b/contrib/lib/src/msgpack.rs @@ -24,8 +24,7 @@ use rocket::response::{self, Responder, content}; use rocket::http::Status; use rocket::form::prelude as form; -use serde::Serialize; -use serde::de::{Deserialize, DeserializeOwned}; +use serde::{Serialize, Deserialize}; pub use rmp_serde::decode::Error; @@ -194,7 +193,7 @@ impl<'r, T: Serialize> Responder<'r, 'static> for MsgPack { } #[rocket::async_trait] -impl<'v, T: DeserializeOwned + Send> form::FromFormField<'v> for MsgPack { +impl<'v, T: Deserialize<'v> + Send> form::FromFormField<'v> for MsgPack { async fn from_data(f: form::DataField<'v, '_>) -> Result> { Self::from_data(f.request, f.data).await.map_err(|e| { match e {