MZ2009
MZ2009 · Type Error · ERROR
Trait Not Implemented
A type was used where a trait was expected, but the type does not implement that trait.

Cause

A function parameter expects a type that implements a specific trait, but the provided type does not implement it.

Examples

Example 1

Problem:

fn print_area(shape: Drawable) { echo(shape.area()) }
p = Point { x: 1, y: 2 }
print_area(p)

Point does not implement Drawable.

Fix:

Implement the trait for Point, or pass a type that already implements Drawable.

Hint

Check which types implement the required trait.

Suggestion

Implement the trait for the type, or use a different type.

Related