- Hello again and welcome to lesson 13.
This lesson is all about generics.
We begin with the basic syntax
for generic structures and generic functions.
We'll see how to define them and how to use them.
Then, we'll move on to discuss type constraints.
Type constraints enable you to specify basic requirements
for type parameters.
For example, you can specify a type parameter
must implement a certain trait, so you can then depend
on that trait's functionality in your generic code.
For the remainder of the lesson, we'll take a look
at some of the standard generic traits in the Rust library.
We'll take a look
at generic traits named PartialEq, Eq, Hash,
PartialOrd and Ord, cryptic names I know.
We discuss their role in Rust
and we'll see how to implement them in your structures.
We'll wrap up the lesson with a closer look
at how closures work internally inside Rust.
It so happens that when you write a closure,
Rust converts it
into a strap that implements a generic trait.
This enables you to pass closures
as parameters into function, as we shall see.