pub struct Dotenv { /* private fields */ }
Expand description
Dotenv file loader
Implementations§
Source§impl Dotenv
impl Dotenv
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of the Dotenv file loader.
§Examples
# .env
DB_USER=root
DB_PASS=pass
use darkweb_dotenv::Dotenv;
let mut dotenv = Dotenv::new();
dotenv.load(".env").unwrap();
let db_user = std::env::var("DB_USER").unwrap();
Sourcepub fn load_env<Path, EnvKey, DefaultEnv>(
&mut self,
path: Path,
env_key: EnvKey,
default_env: DefaultEnv,
) -> Result<(), Exception>
pub fn load_env<Path, EnvKey, DefaultEnv>( &mut self, path: Path, env_key: EnvKey, default_env: DefaultEnv, ) -> Result<(), Exception>
Loads environment-specific environment variables from multiple .env
files in an hierarchy.
The following files are loaded if they exist, the latter taking precedence over the former:
.env
–> committed environment defaults.env.local
–> uncommitted file with local overrides.env.{APP_ENV}
–> committed environment-specific defaults.env.{APP_ENV}.local
–> uncommitted environment-specific local overrides
§Examples
use darkweb_dotenv::Dotenv;
let mut dotenv = Dotenv::new();
dotenv.load_env(".env", "APP_ENV", "dev").unwrap();
§Exceptions
Exception::FormatException
Exception::PathException
Auto Trait Implementations§
impl Freeze for Dotenv
impl RefUnwindSafe for Dotenv
impl Send for Dotenv
impl Sync for Dotenv
impl Unpin for Dotenv
impl UnwindSafe for Dotenv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more