I've turned everything into String
and it's still complaining. No clue why.
let mut nodes: HashMap<&String, NodeIndex> = HashMap::new();
let mut graph = Graph::<String, u32>::new();
for line in input.split('\n') {
println!("Record: {}", line);
let (container, colors) = parse_line(line);
let node = match nodes.get(&container) {
Some(n) => *n,
None => {
let ni = graph.add_node(container);
nodes.insert(&container, ni);
ni
}
};
for col in colors {
let contained_node = match nodes.get(&container) {
Some(n) => *n,
None => {
let ni = graph.add_node(col);
nodes.insert(&container, ni);
ni
}
};
graph.add_edge(node, contained_node, 0);
}
}
println!("Generated graph: {:?}", graph);
This is parse_line
:
fn parse_line(line: &str) -> (String, Vec<String>) {}
borrowed value does not live long enough
container
dropped here while still borrowed
I don't know who's borrowing it and why it's not living long enough.
I'm passing the self-owned strings to Graph
. Shouldn't that be enough?