macro_rules! with_setters {
($ty:ty { $($items:tt)* }) => {
impl $ty {
with_setters!(@items $($items)*);
}
};
(@items) => {};
(@items $(#[$attr:meta])* $name:ident($field:ident): Some($fty:ty) $(, $($rest:tt)*)?) => {
#[doc = concat!(
"Sets [`", stringify!($field), "`](Self::", stringify!($field), ") to `Some(value)`."
)]
$(#[$attr])*
#[must_use]
pub fn $name(mut self, value: $fty) -> Self {
self.$field = Some(value);
self
}
with_setters!(@items $($($rest)*)?);
};
(@items $(#[$attr:meta])* $name:ident($field:ident): Into($fty:ty) $(, $($rest:tt)*)?) => {
#[doc = concat!("Sets [`", stringify!($field), "`](Self::", stringify!($field), ").")]
$(#[$attr])*
#[must_use]
pub fn $name(mut self, value: impl Into<$fty>) -> Self {
self.$field = value.into();
self
}
with_setters!(@items $($($rest)*)?);
};
(@items $(#[$attr:meta])* $name:ident($field:ident): $fty:ty $(, $($rest:tt)*)?) => {
#[doc = concat!("Sets [`", stringify!($field), "`](Self::", stringify!($field), ").")]
$(#[$attr])*
#[must_use]
pub fn $name(mut self, value: $fty) -> Self {
self.$field = value;
self
}
with_setters!(@items $($($rest)*)?);
};
}