Add new section on trait bounds.

This commit is contained in:
LukeMathWalker
2024-05-23 15:29:42 +02:00
parent 2477f72adc
commit 453d8030e5
32 changed files with 182 additions and 21 deletions

View File

@@ -0,0 +1,4 @@
[package]
name = "trait_bounds"
version = "0.1.0"
edition = "2021"

View File

@@ -0,0 +1,15 @@
// TODO: Add the necessary trait bounds to `min` so that it compiles successfully.
// Refer to `std::cmp` for more information on the traits you might need.
//
// Note: there are different trait bounds that'll make the compiler happy, but they come with
// different _semantics_. We'll cover those differences later in the course when we talk about ordered
// collections (e.g. BTreeMap).
/// Return the minimum of two values.
pub fn min<T>(left: T, right: T) -> T {
if left <= right {
left
} else {
right
}
}