mirror of https://github.com/rwf2/Rocket.git
Allow 'T: Deserialize' in JSON, MessagePack forms.
Previously, 'T: DeserializeOwned' was required needlessly. This allowed 'Json' and 'MsgPack' to borrow from the request.
This commit is contained in:
parent
64e46b7107
commit
dd0c036461
|
@ -24,8 +24,7 @@ use rocket::response::{self, Responder, content};
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
use rocket::form::prelude as form;
|
use rocket::form::prelude as form;
|
||||||
|
|
||||||
use serde::{Serialize, Serializer};
|
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||||
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use serde_json::{json_internal, json_internal_vec};
|
pub use serde_json::{json_internal, json_internal_vec};
|
||||||
|
@ -237,7 +236,7 @@ impl From<JsonError<'_>> for form::Error<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl<'v, T: DeserializeOwned + Send> form::FromFormField<'v> for Json<T> {
|
impl<'v, T: Deserialize<'v> + Send> form::FromFormField<'v> for Json<T> {
|
||||||
fn from_value(field: form::ValueField<'v>) -> Result<Self, form::Errors<'v>> {
|
fn from_value(field: form::ValueField<'v>) -> Result<Self, form::Errors<'v>> {
|
||||||
Ok(Self::from_str(field.value)?)
|
Ok(Self::from_str(field.value)?)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,7 @@ use rocket::response::{self, Responder, content};
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
use rocket::form::prelude as form;
|
use rocket::form::prelude as form;
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::{Serialize, Deserialize};
|
||||||
use serde::de::{Deserialize, DeserializeOwned};
|
|
||||||
|
|
||||||
pub use rmp_serde::decode::Error;
|
pub use rmp_serde::decode::Error;
|
||||||
|
|
||||||
|
@ -194,7 +193,7 @@ impl<'r, T: Serialize> Responder<'r, 'static> for MsgPack<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl<'v, T: DeserializeOwned + Send> form::FromFormField<'v> for MsgPack<T> {
|
impl<'v, T: Deserialize<'v> + Send> form::FromFormField<'v> for MsgPack<T> {
|
||||||
async fn from_data(f: form::DataField<'v, '_>) -> Result<Self, form::Errors<'v>> {
|
async fn from_data(f: form::DataField<'v, '_>) -> Result<Self, form::Errors<'v>> {
|
||||||
Self::from_data(f.request, f.data).await.map_err(|e| {
|
Self::from_data(f.request, f.data).await.map_err(|e| {
|
||||||
match e {
|
match e {
|
||||||
|
|
Loading…
Reference in New Issue