-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds more description in the examples. We also use `unwrap` sometimes when calling `env::var` for simplicity.
- Loading branch information
Showing
7 changed files
with
36 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
//! This example shows finding an env file by filename. | ||
|
||
use dotenvy::EnvLoader; | ||
use std::{ | ||
env, error, fs, io, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
use std::{env, error}; | ||
//! The `load` attribute loads and modifies the environment. | ||
//! | ||
//! This is more ergonomic than the *modify* example. | ||
|
||
use std::env; | ||
|
||
#[dotenvy::load(path = "../env-example", required = true, override_ = true)] | ||
fn main() -> Result<(), Box<dyn error::Error>> { | ||
println!("HOST={}", env::var("HOST")?); | ||
Ok(()) | ||
fn main() { | ||
println!("HOST={}", env::var("HOST").unwrap()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
//! `#[dotenvy::load]` must go before `#[tokio::main]`. | ||
//! This is more ergonomic than the *modify-tokio* example. | ||
//! | ||
//! The attribute macro executes `load_and_modify` before the tokio runtime is spawned. | ||
//! When using this method, `#[dotenvy::load]` be put above `#[tokio::main]`. | ||
|
||
use std::{env, error}; | ||
use std::env; | ||
|
||
#[dotenvy::load(path = "../env-example")] | ||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn error::Error>> { | ||
println!("HOST={}", env::var("HOST")?); | ||
Ok(()) | ||
async fn main() { | ||
println!("HOST={}", env::var("HOST").unwrap()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters