So I am creating queue of (PathBuf, String)
tuples
let mut config_value = config_content.parse::<Value>().unwrap();
let config: &mut _ = config_value.as_table_mut().unwrap();
let root = match config.remove("root") {
Some(r) => config_path.join(r.as_str().unwrap()),
None => config_path
};
let queue: VecDeque<(PathBuf, String)> = VecDeque::from_iter(
config.into_iter().map(
|(k, v)| v.as_table().unwrap().into_iter().map(
|(n, u)| (root.join(k).join(n), u.as_str().unwrap().to_string()))).flatten());
The unfortunate thing is that I got my lifetimes and types messed up
error[E0597]: `k` does not live long enough
--> src\main.rs:46:37
|
46 | |(n, u)| (root.join(k).join(n), u.as_str().unwrap().to_string()))).flatten());
| -------- ^ borrowed value does not live long enough - `k` dropped here while still borrowed
| |
| value captured here
The k
is &String
The join
method requires AsRef<Path>
Not only I don't understand how to fix it (i tried cloning, to_owned
, explicitly borrowing), I also don't understand why it doesn't work "as is".