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.
I find my self doing something like this quite often:
I think it would be nice to have a
env_or_defaultmacro that defaults to a fallback string at compile time if the environment variable cannot be found. I'm thinking of something likeI know the runtime cost isn't that high but if it can be done at compile time, it should be done.