Learn Rust With Entirely Too Many Linked Lists
02

New

A type without methods is a record, not an interface. We attach methods through impl blocks. The first one is a constructor.

  1. Methods live in impl List { ... }. A function with no self is an associated function — call it as List::new(), the same way you'd call a static method.
    impl List {
        pub fn new() -> Self {
            List { head: Link::Empty }
        }
    }
  2. Self (capital S) is shorthand for the type the impl block is on. Use it everywhere instead of repeating List; renaming the type later only touches the line pub struct List and not the constructor.
    let list = List::new();
    // list.head is Link::Empty