Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
1 merge request!471Introduce macro for ThingListBuilder, and use for AuthorityListBuilder
......@@ -85,7 +85,7 @@
macro_rules! define_list_config_builder {
{
$(#[ $docs_and_attrs:meta ])*
pub struct $ListBuilder:ident {
$vis:vis struct $ListBuilder:ident {
$field_vis:vis $things:ident : [$EntryBuilder:ty] $(,)?
}
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
/// during configuration resolution, via the `build` method.
pub struct $ListBuilder {
$vis struct $ListBuilder {
/// The list, as overridden
$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.
/// Then `item` is added.
pub fn append(&mut self, item: $EntryBuilder) -> &mut Self {
$vis fn append(&mut self, item: $EntryBuilder) -> &mut Self {
self.$things
.get_or_insert_with(|| $default)
.push(item);
......@@ -117,7 +117,7 @@ macro_rules! define_list_config_builder {
/// Set the list to the supplied one, discarding any previous settings.
///
/// 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
}
......@@ -125,7 +125,7 @@ macro_rules! define_list_config_builder {
/// Checks whether any calls have been made to set or adjust the list.
///
/// 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()
}
......@@ -135,7 +135,7 @@ macro_rules! define_list_config_builder {
/// a built-in default list will be built and returned;
/// otherwise each applicable item will be built,
/// 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 $things = match &self.$things {
Some($things) => $things,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment