Commit c7104629 authored by Ian Jackson's avatar Ian Jackson
Browse files

list_builder: Allow the struct to not be pub

Really, we probably don't want any of these not to be pub, but it
triggers "unreachable pub" in my test cases, and making it not pub by
mistake seems not very serious, and likely to be noticed.

Making the struct private in the test cases has the useful effect of
checking that all the methods are tested.
parent 83b9fbea
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -85,7 +85,7 @@
macro_rules! define_list_config_builder {
macro_rules! define_list_config_builder {
    {
    {
        $(#[ $docs_and_attrs:meta ])*
        $(#[ $docs_and_attrs:meta ])*
        pub struct $ListBuilder:ident {
        $vis:vis struct $ListBuilder:ident {
            $field_vis:vis $things:ident : [$EntryBuilder:ty] $(,)?
            $field_vis:vis $things:ident : [$EntryBuilder:ty] $(,)?
        }
        }
        built: $Built:ty = $built:expr;
        built: $Built:ty = $built:expr;
@@ -98,7 +98,7 @@ macro_rules! define_list_config_builder {
        ///
        ///
        /// This is a builder pattern struct which will be resolved
        /// This is a builder pattern struct which will be resolved
        /// during configuration resolution, via the `build` method.
        /// during configuration resolution, via the `build` method.
        pub struct $ListBuilder {
        $vis struct $ListBuilder {
            /// The list, as overridden
            /// The list, as overridden
            $field_vis $things: Option<Vec<$EntryBuilder>>,
            $field_vis $things: Option<Vec<$EntryBuilder>>,
        }
        }
@@ -107,7 +107,7 @@ macro_rules! define_list_config_builder {
            ///
            ///
            /// If the list hasn't been set or adjusted yet, it is initialised to the default.
            /// If the list hasn't been set or adjusted yet, it is initialised to the default.
            /// Then `item` is added.
            /// Then `item` is added.
            pub fn append(&mut self, item: $EntryBuilder) -> &mut Self {
            $vis fn append(&mut self, item: $EntryBuilder) -> &mut Self {
                self.$things
                self.$things
                    .get_or_insert_with(|| $default)
                    .get_or_insert_with(|| $default)
                    .push(item);
                    .push(item);
@@ -117,7 +117,7 @@ macro_rules! define_list_config_builder {
            /// Set the list to the supplied one, discarding any previous settings.
            /// Set the list to the supplied one, discarding any previous settings.
            ///
            ///
            /// After `replace` has been called, the default list will no longer be used.
            /// After `replace` has been called, the default list will no longer be used.
            pub fn replace(&mut self, list: impl IntoIterator<Item = $EntryBuilder>) -> &mut Self {
            $vis fn replace(&mut self, list: impl IntoIterator<Item = $EntryBuilder>) -> &mut Self {
                self.$things = Some(list.into_iter().collect());
                self.$things = Some(list.into_iter().collect());
                self
                self
            }
            }
@@ -125,7 +125,7 @@ macro_rules! define_list_config_builder {
            /// Checks whether any calls have been made to set or adjust the list.
            /// Checks whether any calls have been made to set or adjust the list.
            ///
            ///
            /// If `append` or `replace` have been called, this will return `true`.
            /// If `append` or `replace` have been called, this will return `true`.
            pub fn is_unmodified_default(&self) -> bool {
            $vis fn is_unmodified_default(&self) -> bool {
                self.$things.is_none()
                self.$things.is_none()
            }
            }


@@ -135,7 +135,7 @@ macro_rules! define_list_config_builder {
            /// a built-in default list will be built and returned;
            /// a built-in default list will be built and returned;
            /// otherwise each applicable item will be built,
            /// otherwise each applicable item will be built,
            /// and the results collected into a single built list.
            /// and the results collected into a single built list.
            pub fn build(&self) -> Result<$Built, $crate::ConfigBuildError> {
            $vis fn build(&self) -> Result<$Built, $crate::ConfigBuildError> {
                let default_buffer;
                let default_buffer;
                let $things = match &self.$things {
                let $things = match &self.$things {
                    Some($things) => $things,
                    Some($things) => $things,