Traits
A trait is a set of requirements that a type must implement. You can think of it as a contract: a type that conforms to a trait guarantees that it implements all of the features of the trait.
Traits are similar to Java interfaces, C++ concepts, Swift protocols, and Rust traits. If you're familiar with any of those features, Mojo traits solve the same basic problem.
You've probably already seen some traits, like Copyable and Movable, used in
example code. This section describes how traits work, how to use existing
traits, and how to define your own traits.
Background
In dynamically-typed languages like Python, you don't need to explicitly declare that two classes are similar. This is easiest to show by example: