pub enum List { Empty, Elem(i32, Box<List>), }
instead of :
pub struct List { head: Link, }
enum Link { Empty, Some(Box<Node>), }
struct Node { elem: i32, next: Link, }
pub enum List { Empty, Elem(i32, Box<List>), }
instead of :
pub struct List { head: Link, }
enum Link { Empty, Some(Box<Node>), }
struct Node { elem: i32, next: Link, }
I thought Aria's "Entirely Too Many Lists" tutorial actually tries to build this, but it actually doesn't, she draws you the resulting "list" and then is like, OK, that's clearly not what we want, let's build an actual (bad, slow, wasteful) linked list as our first attempt.
The difference really lies in the fact that i now have some data stored on the stack (The element) and some data stored on the heap because it's recursive. Was just a random example of where it's poor practice. As others have noted, linkedlists are a terrible data structure to begin with.