utils.rs

 1/// This macro generates a struct and a corresponding struct with optional fields.
 2///
 3/// It takes as input the name of the struct to be generated, the name of the struct with optional fields,
 4/// and a list of field names along with their types.
 5///
 6/// # Example
 7/// ```
 8/// generate_struct_with_overrides!(
 9///     MyStruct,
10///     MyStructOverride,
11///     field1: i32,
12///     field2: String
13/// );
14/// ```
15/// This will generate the following structs:
16/// ```
17/// pub struct MyStruct {
18///     pub field1: i32,
19///     pub field2: String,
20/// }
21///
22/// pub struct MyStructOverride {
23///     pub field1: Option<i32>,
24///     pub field2: Option<String>,
25/// }
26/// ```
27#[macro_export]
28macro_rules! generate_struct_with_overrides {
29    ($struct_name:ident, $struct_override_name:ident, $($field:ident: $type:ty),*) => {
30        pub struct $struct_name {
31            $(
32                pub $field: $type,
33            )*
34        }
35
36        #[allow(dead_code)]
37        pub struct $struct_override_name {
38            $(
39                pub $field: Option<$type>,
40            )*
41        }
42    };
43}