Disable some code (and fix others) when no features are enabled

This commit is contained in:
Lukas Kalbertodt
2021-07-28 12:38:50 +02:00
parent 1a8e9440cc
commit 4f4f42e8f3
4 changed files with 58 additions and 9 deletions

View File

@@ -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),