Traits
Last updated
What is Traits?
Traits in Rust define behaviors that are shared among different data types. Implementing traits for data types is a great way to group method signatures together and define a set of behaviors your types require. Essentially, anything with a certain trait applied to it will "inherit" the behavior of that trait's methods, but this is not the same thing as inheritance found in object-oriented programming languages.
Traits are abstract; it's not possible to create instances of traits. However, we can define pointers of trait types, and these can hold any data type that implements the trait. A trait is implemented for something else with the syntax impl TraitAbc for Xyz {...}, which can be a concrete type or another trait.
Free resources to learn Traits
More in stage 3: Error Handling
Traits: common questions
Can I learn Traits in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Traits in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Traits tutorial for beginners?
It is lesson 17 of 122 in the free Rust roadmap, in stage 3, Error Handling. If you are new to Rust, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.