是否可以在编译时从环境变量初始化变量?
Is it possible to initialize a variable from an environment variable at compilation time?
我想在编译期间初始化一个变量。比如我想在编译代码的时候把变量VAR
初始化为VALUE
:
match env::var("VAR") {
Ok(value) => println!("Ok {}", value),
Err(e) => println!("Error ({})", e),
};
但是,我想在 no_std
上下文中执行此操作,因此,我无法使用 std::env
访问环境。可以这样做吗?
env::var
not 在编译时得到评估:
Fetches the environment variable key from the current process.
您正在寻找 std::env!
/ core::env!
or std::option_env!
/ core::option_env!
.
我想在编译期间初始化一个变量。比如我想在编译代码的时候把变量VAR
初始化为VALUE
:
match env::var("VAR") {
Ok(value) => println!("Ok {}", value),
Err(e) => println!("Error ({})", e),
};
但是,我想在 no_std
上下文中执行此操作,因此,我无法使用 std::env
访问环境。可以这样做吗?
env::var
not 在编译时得到评估:
Fetches the environment variable key from the current process.
您正在寻找 std::env!
/ core::env!
or std::option_env!
/ core::option_env!
.