rocket/serde/mod.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
//! Serialization and deserialization support.
//!
//! * JSON support is provided by the [`Json`](json::Json) type.
//! * MessagePack support is provided by the [`MsgPack`](msgpack::MsgPack) type.
//! * UUID support is provided by the [`UUID`](uuid) type.
//!
//! Types implement one or all of [`FromParam`](crate::request::FromParam),
//! [`FromForm`](crate::form::FromForm), [`FromData`](crate::data::FromData),
//! and [`Responder`](crate::response::Responder).
//!
//! ## Deriving `Serialize`, `Deserialize`
//!
//! For convenience, Rocket re-exports `serde`'s `Serialize` and `Deserialize`
//! traits and derive macros from this module. However, due to Rust's limited
//! support for derive macro re-exports, using the re-exported derive macros
//! requires annotating structures with `#[serde(crate = "rocket::serde")]`:
//!
//! ```rust
//! use rocket::serde::{Serialize, Deserialize};
//!
//! #[derive(Serialize, Deserialize)]
//! #[serde(crate = "rocket::serde")]
//! struct MyStruct {
//! foo: String,
//! }
//! ```
//!
//! If you'd like to avoid this extra annotation, you must depend on `serde`
//! directly via your crate's `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! serde = { version = "1.0", features = ["derive"] }
//! ```
#[doc(inline)]
pub use serde::ser::{Serialize, Serializer};
#[doc(inline)]
pub use serde::de::{Deserialize, DeserializeOwned, Deserializer};
#[doc(hidden)]
pub use serde::*;
#[cfg(feature = "json")]
#[cfg_attr(nightly, doc(cfg(feature = "json")))]
pub mod json;
#[cfg(feature = "msgpack")]
#[cfg_attr(nightly, doc(cfg(feature = "msgpack")))]
pub mod msgpack;
#[cfg(feature = "uuid")]
#[cfg_attr(nightly, doc(cfg(feature = "uuid")))]
pub mod uuid;