[][src]Struct darkweb_dotenv::Dotenv

pub struct Dotenv { /* fields omitted */ }

Dotenv file loader

Implementations

impl Dotenv[src]

pub fn new() -> Self[src]

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();

pub fn load<Path>(&mut self, path: Path) -> Result<(), Exception> where
    Path: AsRef<str>, 
[src]

Loads environment variables from file a .env file.

Examples

use darkweb_dotenv::Dotenv;

let mut dotenv = Dotenv::new();
dotenv.load(".env").unwrap();

Exceptions

  • Exception::FormatException
  • Exception::PathException

pub fn overload<Path>(&mut self, path: Path) -> Result<(), Exception> where
    Path: AsRef<str>, 
[src]

Loads environment variables from a .env file and overwrites exiting environment variables.

Examples

use darkweb_dotenv::Dotenv;

let mut dotenv = Dotenv::new();
dotenv.overload(".env").unwrap();

Exceptions

  • Exception::FormatException
  • Exception::PathException

pub fn load_env<Path, EnvKey, DefaultEnv>(
    &mut self,
    path: Path,
    env_key: EnvKey,
    default_env: DefaultEnv
) -> Result<(), Exception> where
    Path: AsRef<str>,
    EnvKey: AsRef<str>,
    DefaultEnv: AsRef<str>, 
[src]

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 RefUnwindSafe for Dotenv

impl Send for Dotenv

impl Sync for Dotenv

impl Unpin for Dotenv

impl UnwindSafe for Dotenv

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.