Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default value macro #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

jharrilim
Copy link

This PR adds an alternative macro, dotenv_or_default, which will provide a default value if the environment variable does not exist.

Example:

#[macro_use]
extern crate dotenv_codegen;

use actix_web::{
    App,
    HttpServer,
};

#[actix_rt::main]
pub async fn main() -> std::io::Result<()> {
  let hostname = dotenv_or_default!("HOSTNAME", "127.0.0.1");
  let port = dotenv_or_default!("PORT", "8080");
  let url = format!("{}:{}", hostname, port);
  let server = HttpServer::new(|| { App::new() })
    .bind(url)?
    .run()
    .await
}

@codecov
Copy link

codecov bot commented Aug 22, 2020

Codecov Report

Merging #61 into master will decrease coverage by 5.06%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
- Coverage   86.77%   81.71%   -5.07%     
==========================================
  Files           7        7              
  Lines         242      257      +15     
==========================================
  Hits          210      210              
- Misses         32       47      +15     
Impacted Files Coverage Δ
dotenv_codegen_implementation/src/lib.rs 0.00% <0.00%> (ø)
dotenv/src/find.rs 90.90% <0.00%> (+3.95%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c1a77b...2dc9272. Read the comment docs.

.gitignore Outdated Show resolved Hide resolved
dotenv_codegen/tests/ui/dotenv_no_args.rs Outdated Show resolved Hide resolved
dotenv_codegen/tests/ui/dotenv_or_default_no_args.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,16 @@
error: proc-macro derive panicked
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this file added intentionally? I can't see a place that it is used.

Copy link
Author

@jharrilim jharrilim Aug 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These stderr files are generated for the tests that use trybuild. It compares this to the stderr from compiling the associated rs file: https://github.com/dtolnay/trybuild#workflow

edit: This style of test is also used in the Rust project itself!
https://github.com/rust-lang/rust/tree/master/src/test/ui

dotenv_codegen_implementation/src/lib.rs Outdated Show resolved Hide resolved
jharrilim added a commit to jharrilim/dotenv that referenced this pull request Aug 23, 2020
jharrilim added a commit to jharrilim/dotenv that referenced this pull request Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants