0Pricing
Mojo Academy · Lesson

The __moveinit__ Method

Define how your type moves.

Defining How to Move

To move a value, Mojo calls a special method named __moveinit__. It builds a new instance by taking over an old one. 🚚

It Runs on Transfer

When you use the caret transfer operator, __moveinit__ fires. It relocates the value instead of duplicating its data.

var b = a^   # calls __moveinit__

All lessons in this course

  1. Copy vs Move Semantics
  2. The __copyinit__ Method
  3. The __moveinit__ Method
  4. Destruction and __del__
← Back to Mojo Academy