5 releases
0.2.0 | Jul 14, 2024 |
---|---|
0.1.3 | May 24, 2024 |
0.1.2 | May 23, 2024 |
0.1.1 | May 21, 2024 |
0.1.0 | May 20, 2024 |
#2125 in Procedural macros
373 downloads per month
Used in pgp-sig2dot
5KB
Serialize Display Adapter Macro Derive
use serde::Serialize;
use serialize_display_adapter_macro_derive::PrettyJsonSerializeDisplayAdapter;
#[derive(Serialize, PrettyJsonSerializeDisplayAdapter)]
struct Demo<'a> {
name: &'a str,
age: u8,
}
fn main() {
let name = "root";
let demo = Demo {
name: name.as_ref(),
age: 42,
};
print!("{}", demo)
}
// Should print:
//
// {
// "name": "root",
// "age": 42
// }
lib.rs
:
use serde::Serialize;
use serialize_display_adapter_macro_derive::PrettyJsonSerializeDisplayAdapter;
#[derive(Serialize, PrettyJsonSerializeDisplayAdapter)]
struct Demo<'a> {
name: &'a str,
age: u8,
}
fn main() {
let name = "root";
let demo = Demo {
name: name.as_ref(),
age: 42,
};
print!("{}", demo)
}
Should print:
{
"name": "root",
"age": 42
}
Dependencies
~230–670KB
~16K SLoC