Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.02 KB | None | 0 0
  1. use std::collections::HashMap;
  2.  
  3. struct Node<'a> {
  4.    name : &'a str,
  5.     children : Vec<Node<'a>>,
  6. }
  7.  
  8.  
  9. fn append_children(node : &mut Node, nodes : &HashMap<&str, Vec<&str>>) {
  10.    if let Some(n_arr) = nodes.get(node.name) {
  11.        for n in n_arr {
  12.            node.children.push(Node { name : n.clone(), children : Vec::new() });
  13.            append_children(&mut node.children[node.children.len()-1], nodes);
  14.        }
  15.    }
  16. }
  17.  
  18.  
  19. ---
  20.  
  21. error[E0623]: lifetime mismatch
  22.  --> src/main.rs:11:32
  23.   |
  24. 8  | fn append_children(node : &mut Node, nodes : &HashMap<&str, Vec<&str>>) {
  25.   |                                ----                             ---- these two types are declared with different lifetimes...
  26. ...
  27. 11 |             node.children.push(Node { name : n.clone(), children : Vec::new() });
  28.   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...but data from `nodes` flows into `node` here
  29.  
  30. error: aborting due to previous error
  31.  
  32. error: could not compile `hello_cargo4`.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement