aboutsummaryrefslogtreecommitdiff
path: root/niri-config/src/macros.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-09-20 12:57:41 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-10-02 09:33:08 +0300
commite739ce8171705dd0b87c317cc0f4509b7f16f6df (patch)
treeb4cd995410c63da9a1b9453cd5b56ee890242d0e /niri-config/src/macros.rs
parenta2727ba2c9cfb22e4184235c6dfd8d8819328169 (diff)
downloadniri-e739ce8171705dd0b87c317cc0f4509b7f16f6df.tar.gz
niri-e739ce8171705dd0b87c317cc0f4509b7f16f6df.tar.bz2
niri-e739ce8171705dd0b87c317cc0f4509b7f16f6df.zip
config: Add merge!() macros to reduce boilerplate
Diffstat (limited to 'niri-config/src/macros.rs')
-rw-r--r--niri-config/src/macros.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/niri-config/src/macros.rs b/niri-config/src/macros.rs
new file mode 100644
index 00000000..380111e2
--- /dev/null
+++ b/niri-config/src/macros.rs
@@ -0,0 +1,37 @@
+macro_rules! merge_clone_opt {
+ (($self:expr, $part:expr), $($field:ident),+ $(,)*) => {
+ $(
+ if $part.$field.is_some() {
+ $self.$field.clone_from(&$part.$field);
+ }
+ )+
+ };
+}
+
+macro_rules! merge_color_gradient_opt {
+ (($self:expr, $part:expr), $(($color:ident, $gradient:ident)),+ $(,)*) => {
+ $(
+ if let Some(x) = $part.$color {
+ $self.$color = Some(x);
+ $self.$gradient = None;
+ }
+ if let Some(x) = $part.$gradient {
+ $self.$gradient = Some(x);
+ }
+ )+
+ };
+}
+
+macro_rules! merge_on_off {
+ (($self:expr, $part:expr)) => {
+ if $part.off {
+ $self.off = true;
+ $self.on = false;
+ }
+
+ if $part.on {
+ $self.off = false;
+ $self.on = true;
+ }
+ };
+}