Derive Macro display_json::DebugAsJson
source · [−]#[derive(DebugAsJson)]
Expand description
Implements Debug as a wrapper around serde_json::to_string.
See this crate’s documentation for more examples on how you can use this custom derive procedural macro.
Example:
use serde::Serialize;
use display_json::DebugAsJson;
#[derive(Serialize, DebugAsJson)]
#[serde(tag = "type")]
#[serde(content = "val")]
#[serde(rename_all = "lowercase")]
enum EitherStringOrNum {
String(String),
Num(f64),
}
let num = EitherStringOrNum::Num(12.);
assert_eq!(format!("{:?}", num), r#"{"type":"num","val":12.0}"#);
let string = EitherStringOrNum::String("hello".to_owned());
assert_eq!(
format!("{:?}", string),
r#"{"type":"string","val":"hello"}"#,
);