March 2018
Intermediate to advanced
272 pages
7h 4m
English
You can check environment variables at compile time by using the env!("VAR") and option_env!("VAR") macros. The first will retrieve the environment variable as &'static str. If the variable is not defined, the compilation will fail. The option_env!() macro avoids this by returning an Option::None if the environment variable is not set and an Option::Some(&'static str) if the variable is set:
const THE_KEY: &str = env!("KEY");
Read now
Unlock full access