rocket_community/serde/
mod.rs

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