// Created on savesnippets.com · https://savesnippets.com/Vxi5Xz78leXcj0 use std::fmt::Display; use std::ops::Add; // Inline bound syntax — fine for one constraint fn largest(list: &[T]) -> T { let mut max = list[0]; for &x in &list[1..] { if x > max { max = x; } } max } // `where` clause — clearer when there are many bounds fn print_sum(a: T, b: U) -> impl Display where T: Display + Add, U: Display + Copy, { format!("{} + {} = {}", a, b, a + b) } fn main() { println!("{}", largest(&[3, 1, 4, 1, 5, 9, 2, 6])); // 9 println!("{}", largest(&[3.0, 1.5, 4.2, 1.1])); // 4.2 println!("{}", print_sum(2, 3)); // 2 + 3 = 5 }