-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Open
Milestone
Description
- I have checked the latest
mainbranch to see if this has already been fixed - I have searched existing issues and pull requests for duplicates
URL to the section(s) of the book with this problem:
Description of the problem:
Let’s briefly look at the syntax of specifying generic type parameters, trait bounds, and lifetimes all in one function!
But it doesn't really combine these features. It just uses each of them separately, so it doesn't feel like there's anything new here (besides putting 'a and T together in the angle brackets).
Suggested fix:
Use PartialOrd as the trait bound to create a generic larger function:
fn larger<'a, T>(
x: &'a T,
y: &'a T,
) -> &'a T
where
T: PartialOrd,
{
if *x > *y {
x
} else {
y
}
}