#![cfg(feature = "macros")]
#[doc(hidden)]
#[macro_export]
macro_rules! config {
(
$(#[$attr:meta])*
$name:ident {$($field:ident: $T:ty $(= $val:expr)?),* $(,)?}
) => {
$(#[$attr])*
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(rename_all = "snake_case"),
)]
#[repr(C)]
#[derive(Clone, Debug, Default, PartialEq, PartialOrd)]
pub struct $name {
$(pub $field: $T),*
}
impl $name {
config!(@impl $($field: $T $(= $val)?),*);
}
};
(@impl $($field:ident: $T:ty $(= $val:expr)?),* $(,)?) => {
pub fn new() -> Self {
Self {
$($field: Default::default()),*
}
}
paste::paste! {
$(
pub const fn $field(&self) -> &$T {
&self.$field
}
pub const fn [<$field _mut>](&mut self) -> &mut $T {
&mut self.$field
}
pub fn [<set_ $field>](&mut self, value: $T) -> &mut Self {
self.$field = value;
self
}
pub fn [<with_ $field>](self, $field: $T) -> Self {
Self {
$field,
..self
}
}
)*
}
};
}