Skip to main content

config/prelude/
env.rs

1use crate::{env, Builder};
2
3/// Defines environment variable extension methods for a [configuration builder](Builder).
4pub trait EnvVarsExt: Sized {
5    /// Adds environment variables as a configuration source.
6    fn add_env_vars(self) -> Self {
7        self.add_env_vars_with_prefix("")
8    }
9
10    /// Adds environment variables as a configuration source.
11    ///
12    /// # Arguments
13    ///
14    /// * `prefix` - The prefix that environment variable names must start with. The prefix will be removed from
15    ///   the environment variable names.
16    fn add_env_vars_with_prefix<S: Into<String>>(self, prefix: S) -> Self;
17}
18impl EnvVarsExt for Builder {
19    fn add_env_vars_with_prefix<S: Into<String>>(mut self, prefix: S) -> Self {
20        self.add(env::Provider::new(prefix));
21        self
22    }
23}