trait-concept
Serde Serialize: convert a typed value
Derive a format-independent serialization implementation. A serializer such as serde_json chooses the concrete representation. Serde and serde_json are external crates; use the staged Cargo manifest. Expected stdout (not executed): {"id":7} Common mistake: Assuming Serialize itself produces JSON.
Formal Syntax & Structure
rust syntaxrust
#[derive(serde::Serialize)]Working Example
Example Snippetrust
fn main() { #[derive(serde::Serialize)] struct Item { id: u32 } let item = Item { id: 7 }; println!("{}", serde_json::to_string(&item).unwrap());}