pub trait DotEnvParserConfig: Parser {
// Provided methods
fn additional_dotenv_files(&self) -> Option<Vec<PathBuf>> { ... }
fn dotenv_can_override(&self) -> bool { ... }
}Expand description
automatic dotenv processing configuration
Available configuration for the DotEnvParser trait.
Default implementations are what you’d expect. Use this derive macro for typical use cases.
§Order Matters!
Environment variables are processed/set in this order:
- Preexisting variables already defined in environment.
- The
.envfile, if present. additional_dotenv_filessupplied file(s) (sequentially, as supplied).
Keep in mind:
- Depending on
dotenv_can_override, environment variable values may be the first or last processed/set. additional_dotenv_filesshould be supplied in the order to be processed.
§Examples
#[derive(DotEnvDefault)]
struct Args {}
#[entrypoint::entrypoint]
fn main(args: Args) -> anyhow::Result<()> {
// .env variables should now be in the environment
for (key, value) in std::env::vars() {
println!("{key}: {value}");
}
}Provided Methods§
Sourcefn additional_dotenv_files(&self) -> Option<Vec<PathBuf>>
fn additional_dotenv_files(&self) -> Option<Vec<PathBuf>>
additional dotenv files to process
Default behavior is to only use .env (i.e. no additional files).
This preserves the stock/default dotenvy behavior.
§Examples
struct Args {
/// allow user to pass in additional env files
#[arg(long)]
user_dotenv: Option<std::path::PathBuf>,
}
impl entrypoint::DotEnvParserConfig for Args {
fn additional_dotenv_files(&self) -> Option<Vec<std::path::PathBuf>> {
self.user_dotenv.clone().map(|p| vec![p])
}
}Sourcefn dotenv_can_override(&self) -> bool
fn dotenv_can_override(&self) -> bool
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.