I'm trying to use lazy_static crate to initialize some static variables which assigned values by reading some environment variables in build.rs. What I'm trying to achieve is similar to this post.
My code is following:
lazy_static! {
static _spdk_dir : String = match env::var("SPDK_DIR") {
Ok(val) => val,
Err(_e) => panic!("SPDK_DIR is not defined in the environment")
};
static _dpdk_dir: String = match env::var("DPDK_DIR") {
Ok(val) => val,
Err(_e) => panic!("DPDK_DIR is not defined in the environment")
};
}
After running cargo test, the compiler gives error: no rules expected the token _spdk_dir. I can get rid of this error by adding the keyword ref after static
but doing so will lead another error when use the variable with println!:
println!("cargo:warning={}", _spdk_dir);
The error is _spdk_dir doesn't implement std::fmt::Display
I'm wondering how can I solve the problem? Thanks!