mirror of
https://github.com/OMGeeky/confique.git
synced 2026-01-17 08:59:34 +01:00
Disable some code (and fix others) when no features are enabled
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#[cfg(any(feature = "toml", feature = "yaml"))]
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::{Config, Error, File, Partial};
|
||||
use crate::{Config, Error, Partial};
|
||||
|
||||
#[cfg(any(feature = "toml", feature = "yaml"))]
|
||||
use crate::File;
|
||||
|
||||
|
||||
|
||||
/// Convenience builder to configure, load and merge multiple configuration
|
||||
@@ -25,6 +30,7 @@ impl<C: Config> Builder<C> {
|
||||
///
|
||||
/// The file is not considered required: if the file does not exist, an
|
||||
/// empty configuration (`C::Partial::empty()`) is used for this layer.
|
||||
#[cfg(any(feature = "toml", feature = "yaml"))]
|
||||
pub fn file(mut self, path: impl Into<PathBuf>) -> Self {
|
||||
self.sources.push(Source::File(path.into()));
|
||||
self
|
||||
@@ -51,6 +57,7 @@ impl<C: Config> Builder<C> {
|
||||
let mut partial = C::Partial::empty();
|
||||
for source in self.sources {
|
||||
let layer = match source {
|
||||
#[cfg(any(feature = "toml", feature = "yaml"))]
|
||||
Source::File(path) => File::new(path)?.load()?,
|
||||
Source::Env => C::Partial::from_env()?,
|
||||
Source::Preloaded(p) => p,
|
||||
@@ -64,6 +71,7 @@ impl<C: Config> Builder<C> {
|
||||
}
|
||||
|
||||
enum Source<C: Config> {
|
||||
#[cfg(any(feature = "toml", feature = "yaml"))]
|
||||
File(PathBuf),
|
||||
Env,
|
||||
Preloaded(C::Partial),
|
||||
|
||||
Reference in New Issue
Block a user