Struct Dotenv

Source
pub struct Dotenv { /* private fields */ }
Expand description

Dotenv file loader

Implementations§

Source§

impl Dotenv

Source

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

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

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
Source

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

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
Source

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

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.