Menu

[Rust Guide] 10.3. Trait Pt.1 - Trait Definitions, Bounds, and Implementation
📰
0

[Rust Guide] 10.3. Trait Pt.1 - Trait Definitions, Bounds, and Implementation

DEV Community·SomeB1oody·about 1 month ago
#2NfcXzRW
Reading 0:00
15s threshold

If you find this helpful, please like, bookmark, and follow. To keep learning along, follow this series. 10.3.1 What Is a Trait Trait means feature or characteristic. Traits are used to describe to the Rust compiler what capabilities a type has and which behaviors it can share with other types . Traits define shared behavior in an abstract way. There is also the concept of trait bounds, which can constrain a generic type parameter to a type that implements a specific behavior . In other words, it requires the generic type parameter to implement certain traits. Traits in Rust are somewhat similar to interfaces in other languages , but there are still differences. 10.3.2 Defining a Trait The behavior of a type is made up of the methods that the type itself can call. Sometimes different types have the same methods, and in that case we say those types share the same behavior. Traits provide a way to group methods together, thereby defining the behavior required to achieve a certain purpose.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More