macro_rules! builder_collections {
(
$builder:ident, $state:ident;
$($kind:ident $field:ident / $single:ident: $item:ty, $target:expr, $what:literal;)*
) => {
impl<S: $state::State> $builder<S> {
$($crate::command::builder_collections!(@$kind $field, $single, $item, $target, $what);)*
}
};
(@vec $field:ident, $single:ident, $item:ty, $target:expr, $what:literal) => {
#[doc = concat!("Replaces every value of the ", $target, ": ", $what, ".")]
#[must_use]
pub fn $field(mut self, items: impl IntoIterator<Item = impl Into<$item>>) -> Self {
self.$field = items.into_iter().map(Into::into).collect();
self
}
#[doc = concat!("Adds one value of the ", $target, ": ", $what, ".")]
#[must_use]
pub fn $single(mut self, item: impl Into<$item>) -> Self {
self.$field.push(item.into());
self
}
};
(@map $field:ident, $single:ident, $item:ty, $target:expr, $what:literal) => {
#[doc = concat!("Replaces every entry of the ", $target, ": ", $what, ".")]
#[must_use]
pub fn $field<K: Into<$item>, V: Into<$item>>(
mut self,
entries: impl IntoIterator<Item = (K, V)>,
) -> Self {
self.$field = entries
.into_iter()
.map(|(key, value)| (key.into(), value.into()))
.collect();
self
}
#[doc = concat!("Adds one entry of the ", $target, ": ", $what, ".")]
#[must_use]
pub fn $single(mut self, key: impl Into<$item>, value: impl Into<$item>) -> Self {
self.$field.insert(key.into(), value.into());
self
}
};
}
pub(crate) use builder_collections;