Version: 1.1.0

Ownership cheat sheet

Who owns a value, and how it is allowed to move.

Essentials

  • read borrows without changing the value.
  • mut borrows and can assign to fields.
  • owned takes the value. Callers pass it with ^.
  • The last use destroys an owned value.
  • A returned value transfers ownership to the caller.

Example

fn take(owned s: String):
    print(s)

fn main():
    var s = String("x")
    take(s^)

Keep in mind

After ^, the source name is empty. Using it is a compile error.