pub struct EnvFileSource { /* private fields */ }Expand description
Loads secrets from a .env file.
The file is parsed once at construction time. Supported syntax:
KEY=VALUE— plain valueKEY="quoted value"— double-quoted (quotes stripped)KEY='quoted value'— single-quoted (quotes stripped)export KEY=VALUE— optionalexportprefix, followed by spaces or tabs (ignored)# comment— ignored- Blank lines — ignored
- Inline comments:
KEY=VALUE # comment(unquoted values only)
Implementations§
Source§impl EnvFileSource
impl EnvFileSource
Sourcepub fn load(path: impl Into<PathBuf>) -> Result<Self, SecretError>
pub fn load(path: impl Into<PathBuf>) -> Result<Self, SecretError>
Load from path.
Returns SecretError::FileNotFound if the file does not exist.
Use this when the path was explicitly provided by the user (e.g. via
--env-file).
Sourcepub fn load_optional(
path: impl Into<PathBuf>,
) -> Result<Option<Self>, SecretError>
pub fn load_optional( path: impl Into<PathBuf>, ) -> Result<Option<Self>, SecretError>
Load from path if it exists, or return None if the file is absent.
Use this for the default .env path so that projects without a .env
file are not forced to create one.
Trait Implementations§
Source§impl Debug for EnvFileSource
impl Debug for EnvFileSource
Source§impl SecretSource for EnvFileSource
impl SecretSource for EnvFileSource
Auto Trait Implementations§
impl Freeze for EnvFileSource
impl RefUnwindSafe for EnvFileSource
impl Send for EnvFileSource
impl Sync for EnvFileSource
impl Unpin for EnvFileSource
impl UnsafeUnpin for EnvFileSource
impl UnwindSafe for EnvFileSource
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