mirror of https://github.com/rwf2/Rocket.git
parent
40d11929d7
commit
30fac32978
|
@ -29,12 +29,12 @@ log = "^0.3"
|
||||||
uuid = { version = "^0.4", optional = true }
|
uuid = { version = "^0.4", optional = true }
|
||||||
|
|
||||||
# Serialization and templating dependencies.
|
# Serialization and templating dependencies.
|
||||||
serde = { version = "^0.9", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
serde_json = { version = "^0.9.3", optional = true }
|
serde_json = { version = "1.0", optional = true }
|
||||||
rmp-serde = { version = "^0.12", optional = true }
|
rmp-serde = { version = "^0.13", optional = true }
|
||||||
|
|
||||||
# Templating dependencies only.
|
# Templating dependencies only.
|
||||||
handlebars = { version = "^0.25", optional = true, features = ["serde_type"] }
|
handlebars = { version = "^0.26.1", optional = true }
|
||||||
glob = { version = "^0.2", optional = true }
|
glob = { version = "^0.2", optional = true }
|
||||||
lazy_static = { version = "^0.2", optional = true }
|
lazy_static = { version = "^0.2", optional = true }
|
||||||
tera = { version = "^0.8", optional = true }
|
tera = { version = "^0.10", optional = true }
|
||||||
|
|
|
@ -8,7 +8,8 @@ use rocket::data::{self, Data, FromData};
|
||||||
use rocket::response::{self, Responder, content};
|
use rocket::response::{self, Responder, content};
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::Serialize;
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
|
@ -22,9 +23,9 @@ pub use serde_json::error::Error as SerdeError;
|
||||||
///
|
///
|
||||||
/// If you're receiving JSON data, simply add a `data` parameter to your route
|
/// If you're receiving JSON data, simply add a `data` parameter to your route
|
||||||
/// arguments and ensure the type of the parameter is a `JSON<T>`, where `T` is
|
/// arguments and ensure the type of the parameter is a `JSON<T>`, where `T` is
|
||||||
/// some type you'd like to parse from JSON. `T` must implement `Deserialize`
|
/// some type you'd like to parse from JSON. `T` must implement `Deserialize` or
|
||||||
/// from [Serde](https://github.com/serde-rs/json). The data is parsed from the
|
/// `DeserializeOwned` from [Serde](https://github.com/serde-rs/json). The data
|
||||||
/// HTTP request body.
|
/// is parsed from the HTTP request body.
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// #[post("/users/", format = "application/json", data = "<user>")]
|
/// #[post("/users/", format = "application/json", data = "<user>")]
|
||||||
|
@ -87,7 +88,7 @@ impl<T> JSON<T> {
|
||||||
/// Default limit for JSON is 1MB.
|
/// Default limit for JSON is 1MB.
|
||||||
const LIMIT: u64 = 1 << 20;
|
const LIMIT: u64 = 1 << 20;
|
||||||
|
|
||||||
impl<T: Deserialize> FromData for JSON<T> {
|
impl<T: DeserializeOwned> FromData for JSON<T> {
|
||||||
type Error = SerdeError;
|
type Error = SerdeError;
|
||||||
|
|
||||||
fn from_data(request: &Request, data: Data) -> data::Outcome<Self, SerdeError> {
|
fn from_data(request: &Request, data: Data) -> data::Outcome<Self, SerdeError> {
|
||||||
|
|
|
@ -10,7 +10,8 @@ use rocket::data::{self, Data, FromData};
|
||||||
use rocket::response::{self, Responder, Response};
|
use rocket::response::{self, Responder, Response};
|
||||||
use rocket::http::{ContentType, Status};
|
use rocket::http::{ContentType, Status};
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::Serialize;
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
pub use self::rmp_serde::decode::Error as MsgPackError;
|
pub use self::rmp_serde::decode::Error as MsgPackError;
|
||||||
|
|
||||||
|
@ -22,8 +23,9 @@ pub use self::rmp_serde::decode::Error as MsgPackError;
|
||||||
/// If you're receiving MessagePack data, simply add a `data` parameter to your
|
/// If you're receiving MessagePack data, simply add a `data` parameter to your
|
||||||
/// route arguments and ensure the type of the parameter is a `MsgPack<T>`,
|
/// route arguments and ensure the type of the parameter is a `MsgPack<T>`,
|
||||||
/// where `T` is some type you'd like to parse from MessagePack. `T` must
|
/// where `T` is some type you'd like to parse from MessagePack. `T` must
|
||||||
/// implement `Deserialize` from [Serde](https://github.com/serde-rs/serde). The
|
/// implement `Deserialize` or `DeserializeOwned` from
|
||||||
/// data is parsed from the HTTP request body.
|
/// [Serde](https://github.com/serde-rs/serde). The data is parsed from the HTTP
|
||||||
|
/// request body.
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// #[post("/users/", format = "application/msgpack", data = "<user>")]
|
/// #[post("/users/", format = "application/msgpack", data = "<user>")]
|
||||||
|
@ -100,7 +102,7 @@ fn is_msgpack_content_type(ct: &ContentType) -> bool {
|
||||||
&& (ct.sub() == "msgpack" || ct.sub() == "x-msgpack")
|
&& (ct.sub() == "msgpack" || ct.sub() == "x-msgpack")
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Deserialize> FromData for MsgPack<T> {
|
impl<T: DeserializeOwned> FromData for MsgPack<T> {
|
||||||
type Error = MsgPackError;
|
type Error = MsgPackError;
|
||||||
|
|
||||||
fn from_data(request: &Request, data: Data) -> data::Outcome<Self, Self::Error> {
|
fn from_data(request: &Request, data: Data) -> data::Outcome<Self, Self::Error> {
|
||||||
|
|
|
@ -6,6 +6,6 @@ workspace = "../../"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = { path = "../../lib" }
|
rocket = { path = "../../lib" }
|
||||||
rocket_codegen = { path = "../../codegen" }
|
rocket_codegen = { path = "../../codegen" }
|
||||||
serde = "0.9"
|
serde = "1.0"
|
||||||
serde_json = "0.9"
|
serde_json = "1.0"
|
||||||
serde_derive = "0.9"
|
serde_derive = "1.0"
|
||||||
|
|
|
@ -6,9 +6,9 @@ workspace = "../../"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = { path = "../../lib" }
|
rocket = { path = "../../lib" }
|
||||||
rocket_codegen = { path = "../../codegen" }
|
rocket_codegen = { path = "../../codegen" }
|
||||||
serde = "0.9"
|
serde = "1.0"
|
||||||
serde_derive = "0.9"
|
serde_derive = "1.0"
|
||||||
serde_json = "0.9"
|
serde_json = "1.0"
|
||||||
|
|
||||||
[dependencies.rocket_contrib]
|
[dependencies.rocket_contrib]
|
||||||
path = "../../contrib"
|
path = "../../contrib"
|
||||||
|
|
|
@ -6,9 +6,9 @@ workspace = "../../"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = { path = "../../lib" }
|
rocket = { path = "../../lib" }
|
||||||
rocket_codegen = { path = "../../codegen" }
|
rocket_codegen = { path = "../../codegen" }
|
||||||
serde = "0.9"
|
serde = "1.0"
|
||||||
serde_json = "0.9"
|
serde_json = "1.0"
|
||||||
serde_derive = "0.9"
|
serde_derive = "1.0"
|
||||||
|
|
||||||
[dependencies.rocket_contrib]
|
[dependencies.rocket_contrib]
|
||||||
path = "../../contrib"
|
path = "../../contrib"
|
||||||
|
|
|
@ -6,8 +6,8 @@ workspace = "../../"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = { path = "../../lib" }
|
rocket = { path = "../../lib" }
|
||||||
rocket_codegen = { path = "../../codegen" }
|
rocket_codegen = { path = "../../codegen" }
|
||||||
serde = "0.9"
|
serde = "1.0"
|
||||||
serde_derive = "0.9"
|
serde_derive = "1.0"
|
||||||
|
|
||||||
[dependencies.rocket_contrib]
|
[dependencies.rocket_contrib]
|
||||||
path = "../../contrib"
|
path = "../../contrib"
|
||||||
|
|
|
@ -6,9 +6,9 @@ workspace = "../../"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = { path = "../../lib" }
|
rocket = { path = "../../lib" }
|
||||||
rocket_codegen = { path = "../../codegen" }
|
rocket_codegen = { path = "../../codegen" }
|
||||||
serde = "0.9"
|
serde = "1.0"
|
||||||
serde_json = "0.9"
|
serde_json = "1.0"
|
||||||
serde_derive = "0.9"
|
serde_derive = "1.0"
|
||||||
r2d2 = "0.7"
|
r2d2 = "0.7"
|
||||||
diesel = { version = "0.12", features = ["sqlite"] }
|
diesel = { version = "0.12", features = ["sqlite"] }
|
||||||
diesel_codegen = { version = "0.12", features = ["sqlite"] }
|
diesel_codegen = { version = "0.12", features = ["sqlite"] }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::io::{self, Read, Write, Cursor, BufReader, Chain, Take};
|
use std::io::{self, Read, Write, Cursor, Chain};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -205,7 +205,7 @@ impl Data {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This creates a `data` object from a local data source `data`.
|
/// This creates a `data` object from a local data source `data`.
|
||||||
pub(crate) fn local(mut data: Vec<u8>) -> Data {
|
pub(crate) fn local(data: Vec<u8>) -> Data {
|
||||||
let empty_stream = Cursor::new(vec![])
|
let empty_stream = Cursor::new(vec![])
|
||||||
.chain(NetStream::Local(Cursor::new(vec![])));
|
.chain(NetStream::Local(Cursor::new(vec![])));
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::io::{self, BufRead, Read, Cursor, BufReader, Chain};
|
use std::io::{self, Read, Cursor, Chain};
|
||||||
|
|
||||||
use super::data::BodyReader;
|
use super::data::BodyReader;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue