Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- struct Node<'a> {
- name : &'a str,
- children : Vec<Node<'a>>,
- }
- fn append_children(node : &mut Node, nodes : &HashMap<&str, Vec<&str>>) {
- if let Some(n_arr) = nodes.get(node.name) {
- for n in n_arr {
- node.children.push(Node { name : n.clone(), children : Vec::new() });
- append_children(&mut node.children[node.children.len()-1], nodes);
- }
- }
- }
- ---
- error[E0623]: lifetime mismatch
- --> src/main.rs:11:32
- |
- 8 | fn append_children(node : &mut Node, nodes : &HashMap<&str, Vec<&str>>) {
- | ---- ---- these two types are declared with different lifetimes...
- ...
- 11 | node.children.push(Node { name : n.clone(), children : Vec::new() });
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...but data from `nodes` flows into `node` here
- error: aborting due to previous error
- error: could not compile `hello_cargo4`.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement