Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Rust Programming Tutorial #28 – Defining Traits

23.8K views on YouTube

dcode 42 tutorials here

Similar to interfaces in other languages, traits allow you to set ‘rules’ or ‘requirements’ for a particular struct in order for it to be considered to be ‘something’.

In this video we create a trait called ‘HasVoiceBox’ which says that any Struct implementing this trait must have a speak() and can_speak() method defined on it.

For more information refer to the Rust documentation:
https://doc.rust-lang.org/1.8.0/book/traits.html

If this video helped you out and you’d like to see more, make sure to leave a like and subscribe to dcode!