Rust: Generics, Traits, Lifetimes

Описание к видео Rust: Generics, Traits, Lifetimes

#rust #generic #traits #lifetime

Generics are like a placeholder to another type. Think of a can with food in it. That can is concrete but the food inside is a generic type. The can have soup, beans, corn, or almost anything else inside it.

We have already been using generics with the `Option` type and `Result` type from the error handling chapter.

Here, we will discover how to use generics with our own functions, structs, and methods.

Traits are used to define behavior in a generic way.

And, finally, you cannot talk about generics without talking about lifetimes. This is Rust feature has probably popped up for you in compiler error messages.

Links

Chapter 17 of the Rust Programming book as it relates to the discussion.
https://doc.rust-lang.org/book/ch17-0...

For more complex scenarios involving lifetimes, there’s additional content in the “Rust Reference”. https://doc.rust-lang.org/reference/t...

Комментарии

Информация по комментариям в разработке