mirror of
https://github.com/darkicewolf50/RustBrock.git
synced 2025-07-07 19:47:15 -06:00
.github
.obsidian
HelloWorld
branches
functions_rust
guessing_game
hello_cargo
loops
ownership
rectangles
.gitignore
Collection of Common Data Structs.md
Constants.md
Crates.md
Data Types.md
Enums.md
Error Handling.md
Generic Types Traits and Lifetimes.md
Generics.md
Hash.md
Modules and Use.md
Packages.md
Paths.md
Primitives.md
Project Organization.md
README.md
Reducing_Code_Duplication.md
RustBrock.code-workspace
String.md
Structures.md
Traits.md
Variables.md
Vector.md
data_types.md
ownership.md
879 B
879 B
Generic Types, Traits, and Lifetimes
Generics
A tools for effectively handling the duplication of concepts.
One of these tools is generics
They are abstract stand-ins for concrete types or other properties
We can express the behavior of generics or how they relate to other generics without knowing what type that will be in place when compiling and running the code.
Functions can either take parameters of some generic type or a concrete type (like a i32
or String
) in the same way they take parameters with unknown values to run the same code on multiple concrete values
One example where concrete values were already used was with Option<T>
, Vec<T>
, HashMap<K, V>
and Result<T, E>
This chapter covers 3 things