Core ConceptsOwnership, Borrowing & Lifetimes Preview
All courses

The rules, stated plainly

  1. Each value has one owner.
  2. Only one owner at a time.
  3. When owner goes out of scope, value is dropped.

&str is a string slice (borrowed view). String owns heap data. Prefer &str in function args when you don't need ownership.

Quirk: Lifetimes ('a) tell the compiler how long references are valid. You'll meet them soon. They're friendlier than reputation suggests. Slightly.

Output
Press Run to execute your code.