-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed as not planned
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
I find my self doing something like this quite often:
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
fn main() {
println!("{}", VERSION.unwrap_or("unknown version"));
}
I think it would be nice to have a env_or_default
macro that defaults to a fallback string at compile time if the environment variable cannot be found. I'm thinking of something like
const VERSION: &str = env_or_default!("CARGO_PKG_VERSION", "unknown version");
I know the runtime cost isn't that high but if it can be done at compile time, it should be done.
cypheratheist, matobet, fusion2222, mbStavola, jirutka and 7 more
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.