README.md (737B)
1 # Traits 2 3 A trait is a collection of methods. 4 5 Data types can implement traits. To do so, the methods making up the trait are defined for the data type. For example, the `String` data type implements the `From<&str>` trait. This allows a user to write `String::from("hello")`. 6 7 In this way, traits are somewhat similar to Java interfaces and C++ abstract classes. 8 9 Some additional common Rust traits include: 10 11 - `Clone` (the `clone` method) 12 - `Display` (which allows formatted display via `{}`) 13 - `Debug` (which allows formatted display via `{:?}`) 14 15 Because traits indicate shared behavior between data types, they are useful when writing generics. 16 17 ## Further information 18 19 - [Traits](https://doc.rust-lang.org/book/ch10-02-traits.html)