Easy Rust 068: Traits part 6 - using trait bounds

preview_player
Показать описание
Rewriting our example to use trait bounds, a pretty easy and fun way to make sure that functions are only being used by types that should be using them.

Рекомендации по теме
Комментарии
Автор

Is there a way to enforce somehow that type T should also have a health property. I wanted to display the character health as well in all the attack methods since we had defined health property for Wizard and Ranger as well

nipunsinha
Автор

How do you handle higher-ranked trait bounds on a generic trait? Say the trait uses 2 generic types, one of which has a trait bound like `for<'b> SomeStruct<'b>`?

kheart
Автор

These trait bounds then are restrictions, right? As in, only the types that have these traits can use those functions.

analll
visit shbcf.ru