0Pricing
Mojo Academy · Lesson

The __copyinit__ Method

Define how your type copies itself.

Defining How to Copy

When a value is copied, Mojo calls a special method named __copyinit__. It builds a fresh instance from an existing one. 📋

It Runs on Assignment

Every time a copy happens, like plain assignment, __copyinit__ fires. It is the hook that defines what copying your type means.

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