Rust Annotation Lifetimes Syntax

preview_player
Показать описание
#rust #generic #traits #lifetime #shorts

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.

Рекомендации по теме