From a615b5d4e8cee8569879d5985cbf4c67b0e31347 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 2 May 2024 00:25:47 +0200 Subject: [PATCH] fix(apb): bool setter/getter with rename --- apb/src/macros.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apb/src/macros.rs b/apb/src/macros.rs index 3acd72ef..04cdd615 100644 --- a/apb/src/macros.rs +++ b/apb/src/macros.rs @@ -115,6 +115,12 @@ macro_rules! getter { } }; + ($name:ident::$rename:ident -> bool) => { + fn $name(&self) -> Option { + self.get(stringify!($rename))?.as_bool() + } + }; + ($name:ident::$rename:ident -> &str) => { fn $name(&self) -> Option<&str> { self.get(stringify!($rename))?.as_str() @@ -206,6 +212,17 @@ macro_rules! setter { } }; + ($name:ident::$rename:ident -> bool) => { + paste::item! { + fn [< set_$name >](mut self, val: Option) -> Self { + $crate::macros::set_maybe_value( + &mut self, stringify!($rename), val.map(|x| serde_json::Value::Bool(x)) + ); + self + } + } + }; + ($name:ident -> &str) => { paste::item! { fn [< set_$name >](mut self, val: Option<&str>) -> Self {