Skip to content

Commit

Permalink
allow manually specifying a DefaultSource instead of it only being us…
Browse files Browse the repository at this point in the history
…ed when provided an empty list of sources
  • Loading branch information
tenuous-guidance committed Nov 10, 2023
1 parent 944dab0 commit a14c80e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion confik/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub use self::{
builder::ConfigBuilder,
errors::Error,
secrets::{SecretBuilder, SecretOption, UnexpectedSecret},
sources::{file_source::FileSource, Source},
sources::{file_source::FileSource, DefaultSource, Source},
};
use self::{path::Path, sources::DynSource};

Expand Down
20 changes: 19 additions & 1 deletion confik/src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,26 @@ where
}
}

/// A source to fallback to the provided `Default::default()` implementation, where one exists.
///
/// This will take priority over any `#[confik(default = ...)]`. The main usecase for this would
/// be where the default values for a set of fields require some processing and so you might end up
/// with a struct like:
/// ```
/// #[derive(Configuration)]
/// struct Config {

Check failure on line 45 in confik/src/sources/mod.rs

View workflow job for this annotation

GitHub Actions / Test / stable

cannot find derive macro `Configuration` in this scope
/// #[confik(default = "Config::default().field_1")]
/// field_1: usize,

Check failure on line 47 in confik/src/sources/mod.rs

View workflow job for this annotation

GitHub Actions / Test / stable

cannot find attribute `confik` in this scope
/// #[confik(default = "Config::default().field_2")]
/// field_2: usize,

Check failure on line 49 in confik/src/sources/mod.rs

View workflow job for this annotation

GitHub Actions / Test / stable

cannot find attribute `confik` in this scope
/// #[confik(default = "Config::default().field_3")]
/// field_3: usize,

Check failure on line 51 in confik/src/sources/mod.rs

View workflow job for this annotation

GitHub Actions / Test / stable

cannot find attribute `confik` in this scope
/// }
/// ```
///
/// Otherwise it is recommended to use `#[confik(default = ...)]` for its finer grained control.
#[derive(Debug)]
pub(crate) struct DefaultSource;
pub struct DefaultSource;

impl<T> DynSource<T> for DefaultSource
where
Expand Down

0 comments on commit a14c80e

Please sign in to comment.