fix(apb): bool setter/getter with rename

This commit is contained in:
əlemi 2024-05-02 00:25:47 +02:00
parent bdf48bb7cb
commit a615b5d4e8
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -115,6 +115,12 @@ macro_rules! getter {
}
};
($name:ident::$rename:ident -> bool) => {
fn $name(&self) -> Option<bool> {
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<bool>) -> 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 {