Exerpad
🔥 0
0 XP
Exercise 6 · Chapter: GenericsRequired+50 XP

Fix the Bounds

This function needs to both compare and print values, but it's missing one of the trait bounds! Add it.

Fix the code so it prints:

Winner: banana

Hint: You need both PartialOrd and std::fmt::Display. Use + to combine them.

rust
fn show_winner<T: PartialOrd>(a: T, b: T) {
if a >= b {
println!("Winner: {}", a);
} else {
println!("Winner: {}", b);
}
}

fn main() {
show_winner("apple", "banana");
}
Output
Run your code to see the output here.