Generics
Generics may be used in:
- structs
- functions
- enums
- methods
Functions
Function example:
The function largest
is generic over some type T
.
We can call this function like this:
Structs
Struct example:
Enums
Enum example:
Methods
Method example:
We can also specify a method for a concrete type T
:
Or, we could specify a method only for T
s that implement some traits: