Macro serde_struct_wrapper::serialize_with_root[][src]

macro_rules! serialize_with_root {
    ($root:tt : $inner:ty) => { ... };
}

Generates a custom SerDe Seralize implementation that adds an alternate root key to a Struct during serialization.

Example

extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_struct_wrapper;
#[derive(Serialize)]
#[serde(remote = "Self")]
pub struct Point {
    pub x: i32,
    pub y: i32,
}
serialize_with_root!("point": Point);

The above will serialize a JSON structure like the following:

{
    "point": {
        "x": 1,
        "y": 2
    }
}