Start with the idea
A function may be generic over both a data type and a lifetime. Keep each parameter only when the body needs it; extra bounds make an API less reusable without adding safety.
The choose signature has two independent kinds of abstraction. T: Ord says what operation the body may perform on the values: comparison. 'a says how long the borrowed inputs and returned reference are related. These parameters solve different problems. Replacing the lifetime with a broader trait bound cannot make a dangling reference safe, and adding a lifetime cannot make an incomparable type satisfy Ord.
The result borrows one of the two inputs. Because the body may choose either, the caller must use it only while both candidate sources are valid.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.