helm-rs 0.1.1

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
//! The setters of the collection fields of the derived builders.

/// Writes, inside `impl<S: $state::State> $builder<S>`, two setters for each collection field
/// of a command, which must be declared `#[builder(field)]` (bon generates no setter for it):
/// one that replaces the whole collection (named after the field) and one that adds an item.
///
/// Each entry is `kind field / single: Item, "target", "what it holds";` where `kind` is `vec`
/// (a `Vec<Item>`) or `map` (a `BTreeMap<String, String>`, `Item` is `String`) and `target` says
/// which flag or argument it is, for example ``"repeated flag `--show-only`"``.
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;