Files
2026-03-09 22:30:41 +00:00

1.0 KiB

Implementing operators for a custom Mojo type

This directory contains an example of implementing operators for a custom Mojo struct named Complex, which represents a single complex number. The my_complex.mojo module defines the Complex struct, and main.mojo is a program that imports the module and shows examples of applying the operators to instances of the Complex struct. The test_my_complex.mojo file is a set of unit tests using the Mojo testing framework.

Refer to An example of implementing operators for a custom type in the Mojo manual for a complete explanation of the implementation of the Complex type.

If you have Pixi installed, you can execute the example by running the following command:

pixi run mojo main.mojo

You can run the unit tests by running the following command:

pixi run test