macro_rules! impl_merge {
(
$struct_name:ident {
$(option { $($opt_field:ident),* $(,)? })?
$(nested { $($nest_field:ident),* $(,)? })?
}
) => { ... };
}Expand description
Generates merge() and is_empty() methods for theme structs.
Two field categories:
option { field1, field2, ... }–Option<T>leaf fieldsnested { field1, field2, ... }– nested struct fields with their ownmerge()
For option fields, Some values in the overlay replace the corresponding
fields in self; None fields are left unchanged.
For nested fields, merge is called recursively.
§Examples
use native_theme::impl_merge;
#[derive(Clone, Debug, Default)]
struct MyColors {
accent: Option<String>,
background: Option<String>,
}
impl_merge!(MyColors {
option { accent, background }
});
let mut base = MyColors { accent: Some("blue".into()), background: None };
let overlay = MyColors { accent: None, background: Some("white".into()) };
base.merge(&overlay);
assert_eq!(base.accent.as_deref(), Some("blue"));
assert_eq!(base.background.as_deref(), Some("white"));