Part of the Rust Crash Course: https://www.youtube.com/playlist?list=PL6yRaaP0WPkWRsXJgdnw9lj1vchAaKwfS
Welcome to the Rust Crash Course
In this course, we will be learning Rust from scratch. This course is very fast paced and designed for programmers who already have some experience with another programming language such as Dart or JavaScript or Swift. We will talk about variables, constants, ownership, functions, structures, enumerations, collections such as tuples, vectors, hash-maps and iterators, optionals, error handling, lifetime specifiers, traits, pointers, generics, packages, crates, modules and paths, asynchronous programming and we will also create 2 sample applications using Rust to put all these concepts to use!
In this chapter we are going to learn about traits, or protocols / interfaces as they are also called in Swift and Java. They are called mixins in Dart too. Traits are reusable pieces of code that allow you to plug in the code into existing structs and enums!
Timestamps:
00:00 - Traits
00:42 - Traits are shared functionality
01:36 - Debug trait
02:24 - Create a Person struct
03:01 - Try to print it as a debug value
03:31 - Deriving Debug trait
04:24 - Define your own trait
05:08 - Implement your trait on Person
06:41 - Trait with "new" function
07:43 - Implementing CanInitializeWithFullName for Person
09:47 - Implement fmt::Display for Person
12:05 - Print out "Person" with "{}"
12:30 - The implementation isn't important
13:21 - Traits as parameters
15:10 - Trait bound syntax
16:07 - Conformance to multiple traits
17:28 - Trailing trait bounds using "where"
18:25 - Trait bound results cannot mix multiple types
19:02 - Traits can be implemented on other traits
19:19 - An example of a trait on another trait
19:50 - Define a HasFullName trait
22:03 - Implement HasFullName on HasName
22:48 - Define a Person struct
23:05 - Implement HasName for Person
23:59 - Create a Person instance
24:15 - Get the person's full name
25:04 - Traits and structs in Rust are a must to learn
If you want to support my work, please consider joining my YouTube channel by pressing the Join button!
Twitter: https://twitter.com/vandadnp
LinkedIn: https://linkedin.com/in/vandadnp
Let's get started!