I have the following function
pub fn map_debug_level(&self) -> log::LevelFilter {
let debug_level = match self
.debug
.as_ref()
.unwrap_or(|| -> &HashMap<String, String> {
let mut map = HashMap::new();
map.insert("LEVEL".to_string(), "debug".to_string());
map
}())
.get("LEVEL")
.unwrap()
.as_str()
{
"trace" => log::LevelFilter::Trace,
"debug" => log::LevelFilter::Debug,
"info" => log::LevelFilter::Info,
"warn" => log::LevelFilter::Warn,
"error" => log::LevelFilter::Error,
"off" => log::LevelFilter::Off,
_ => log::LevelFilter::Debug,
};
debug_level
}
The error:
mismatched types
expected reference `&std::collections::HashMap<std::string::String, std::string::String>`
found struct `std::collections::HashMap<std::string::String, std::string::String>`
The hint is to borrow, of course
&map
However that yeilds the following error:
cannot return reference to local variable `map`
returns a reference to data owned by the current function
No idea what i should do, i am still pretty new to borrowing and lifetimes in rust 🙂