Module rocket::serde

source ·
Expand description

Serialization and deserialization support.

  • JSON support is provided by the Json type.
  • MessagePack support is provided by the MsgPack type.
  • UUID support is provided by the UUID type.

Types implement one or all of FromParam, FromForm, FromData, and 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")]:

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:

[dependencies]
serde = { version = "1.0", features = ["derive"] }

Modules§

  • jsonjson
    Automatic JSON (de)serialization support.
  • msgpackmsgpack
    Automatic MessagePack (de)serialization support.
  • uuiduuid
    UUID path/query parameter and form value parsing support.

Traits§

  • A data structure that can be deserialized from any data format supported by Serde.
  • A data structure that can be deserialized without borrowing any data from the deserializer.
  • A data format that can deserialize any data structure supported by Serde.
  • A data structure that can be serialized into any data format supported by Serde.
  • A data format that can serialize any data structure supported by Serde.