#macro-derive #display #adapter #automatic #struct #impl

macro serialize_display_adapter_macro_derive

Automatically impl Display for struct that implementated serde::Serialize

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

#2278 in Procedural macros

37 downloads per month
Used in pgp-sig2dot

MIT license

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

~245–690KB
~16K SLoC