I'm trying to make a read-only map of environment variables.
fn os_env_hashmap() -> HashMap<&'static str, &'static str> {
let mut map = HashMap::new();
use std::env;
for (key,val) in env::vars_os() {
let k = key.to_str();
if k.is_none() { continue }
let v = val.to_str();
if v.is_none() { continue }
k.unwrap();
//map.insert( k.unwrap(), v.unwrap() );
}
return map;
}
Can't seem to uncomment the "insert" line near the bottom without compiler errors about key,val,k, and v being local.
I might be able to fix the compiler error by using String instead of str, but str seems perfect for a read-only result.
Feel free to suggest a more idiomatic way to do this.