not sure I'm completely getting the necessity of Rc; per the book, this would not work: enum List { Cons(i32, &List), Nil, } fn main() { let x = Cons(3, &Nil); } because, the Nil would get dropped before you can take a ref to it
It's very similar to `&str` and `String`. `&str` is nice to pass around, but you often want an owned version instead (imagine if any struct that worked with strings had to be tied to the lifetime of an `&str`)
-
-
I think that's the thing that hadn't clicked: having this: enum List<'a> { Cons(i32, &'a List), Nil, } it's not painful necessarily b/c the &'a List must outlive the outer List -- it's that something else needs to own the inner List
-
i.e. things without owners get dropped, so you'd rather the list/tree/graph/whatever owned all its contents
- 3 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.