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
- Copy vs Move Semantics
- The __copyinit__ Method
- The __moveinit__ Method
- Destruction and __del__