Last active
December 16, 2015 09:59
-
-
Save SiegeLord/5417008 to your computer and use it in GitHub Desktop.
Tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Owned | |
{ | |
Name : ~str | |
} | |
struct Node | |
{ | |
Resource : Owned, | |
Children : ~[Node] | |
} | |
impl Drop for Owned | |
{ | |
fn finalize(&self) | |
{ | |
io::println(self.Name); | |
} | |
} | |
fn new(name : ~str) -> Node | |
{ | |
Node{Resource : Owned{Name : name}, Children : ~[]} | |
} | |
fn spawn_child<'l>(parent : &'l mut Node, name : ~str) -> &'l mut Node | |
{ | |
parent.Children.push(new(name)); | |
&'l mut parent.Children[parent.Children.len() - 1] | |
} | |
fn main() | |
{ | |
let mut parent = ~new(~"parent"); | |
let child = spawn_child(&mut *parent, ~"child"); | |
/*{ | |
let b = parent; | |
}*/ | |
} | |
/* | |
bin.rs:27:3: 27:18 error: loan of mutable field as mutable conflicts with prior loan | |
bin.rs:27 parent.Children.push(new(name)); | |
^~~~~~~~~~~~~~~ | |
bin.rs:28:11: 28:26 note: prior loan as immutable granted here | |
bin.rs:28 &'l mut parent.Children[parent.Children.len() - 1] | |
^~~~~~~~~~~~~~~ | |
error: aborting due to previous error | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment