expression
Transparent newtype wire representation
Serialize or deserialize a single-field wrapper like its contained field, preserving a distinct Rust type in application code. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 12 Common mistake: Confusing Serde transparency with memory layout or repr(transparent).
Formal Syntax & Structure
rust syntaxrust
#[serde(transparent)]Working Example
Example Snippetrust
fn main() { #[derive(serde::Serialize, serde::Deserialize)] #[serde(transparent)] struct ProductId(u64); let id: ProductId = serde_json::from_str("12").unwrap(); println!("{}", serde_json::to_string(&id).unwrap());}