In computer programming, a trait is a language concept that represents a set of methods that can be used to extend the functionality of a class.
Historically, there have been several approaches to solve this without duplicating the code in every class needing the behavior.
This is different from other composition methods in object-oriented programming, where conflicting names are automatically resolved by scoping rules.
On C# 8.0, it is possible to define an implementation as a member of an interface.This example uses a trait to enhance other classes: This allows simulating aspects of multiple inheritance: A trait in Rust declares a set of methods that a type must implement.
[45] Derivable traits include: Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord and Hash.