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
Exactly. Since *something* has to own the inner node, you can't do non-trivial things to lists in a function. e.g. fn list(x: i32, y: i32) -> List<'static> { Cons(x, &Cons(y, &Nil)) } `&Nil` is actually fine since `Nil` is a constant value, but `&Cons(y` is invalid
-
-
Playground example for completeness. Only list2 fails to compile. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=08be5beb0e15553451f4decf0919c969 …
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
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.