From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implement traits

Implement traits - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Implement traits

- [Instructor] Rust provides an abstract way to define the capabilities or functionality of specific data types using traits, which are collections of methods representing a set of behaviors necessary to accomplish some task. When a data type implements a trait, that means it implements those specific methods so they'll be available to use with it. We've already encountered traits in regards to generics which impose bounds to specify that a generic type can be any data type as long as it implements specific traits, and therefore has the necessary methods to use it. If you have experience in other programming languages like C++ or Java, you'll recognize traits as being very similar to a feature in those languages called interfaces, although there are some differences. In addition to a handful of common traits that come standard with Rust, you can also define your own custom traits to specify certain capabilities. To…

Contents