File: patch-attr.rs

package info (click to toggle)
rust-struct-patch 0.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 188 kB
  • sloc: makefile: 2
file content (30 lines) | stat: -rw-r--r-- 803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use serde_with::skip_serializing_none;
use struct_patch::Patch;

#[derive(Default, Patch)]
#[patch(attribute(derive(serde::Serialize, Debug, Default)))]
#[patch(attribute(skip_serializing_none))]
struct Item {
    field_bool: bool,
    field_int: usize,
    field_string: String,
}

// Generated by Patch derive macro
//
// #[derive(Debug, Default)] // pass by patch(attribute(...))
// #[skip_serializing_none] // pass by patch(attribute(...))
// struct ItemPatch {  // pass by patch(name = ...)
//     field_bool: Option<bool>,
//     field_int: Option<usize>,
//     field_string: Option<String>,
// }

fn main() {
    let patch: ItemPatch = Item::new_empty_patch();

    assert_eq!(
        format!("{patch:?}"),
        "ItemPatch { field_bool: None, field_int: None, field_string: None }"
    );
}