flâneur

Jess D

5 followers · 4 following · 360 views

on the atlas — 28

highlights — 6

  • The dot syntax is syntactic sugar for the function-call syntax.
    References and Borrowing - The Rust Programming Language
  • Remember: it’s not a problem that first points to deallocated memory. It’s a problem that we tried to use first after it became invalid.
    What is Ownership? - The Rust Programming Language
  • At L3, the function name.push_str(" Jr.") resizes the string’s heap allocation. This does three things. First, it creates a new larger allocation. Second, it writes “Ferris Jr.” into the new allocation. Third, it frees the original heap memory. first now points to deallocated memory.
    What is Ownership? - The Rust Programming Language
  • Machine code generated from for loops can be more efficient as well because the index doesn’t need to be compared to the length of the array at every iteration.
    Control Flow - The Rust Programming Language
  • You can optionally specify a loop label on a loop that you can then use with break or continue to specify that those keywords apply to the labeled loop instead of the innermost loop. Loop labels must begin with a single quote.
    Control Flow - The Rust Programming Language
  • Note: the semicolon after break counter * 2 is technically optional. break is very similar to return, in that both can optionally take an expression as an argument, both cause a change in control flow. Code after a break or return is never executed, so the Rust compiler treats a break expression and a return expression as having the value unit, or ().
    Control Flow - The Rust Programming Language