#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

#2125 in Procedural macros

Download history 22/week @ 2024-09-16 3/week @ 2024-09-23 10/week @ 2024-09-30 2/week @ 2024-10-07

373 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

~230–670KB
~16K SLoC