use std::fmt::Display;↵
use std::cmp::PartialOrd;↵
↵
#[derive(Debug)]↵
struct Pair<T> {↵
first: T,↵
second: T,↵
}↵
↵
impl<T> Pair<T> {↵
fn new(first: T, second: T) -> Self {↵
Pair { first, second }↵
}↵
}↵
↵
impl<T: Display + PartialOrd> Pair<T> {↵
fn cmp_display(&self) {↵
if self.first >= self.second {↵
println!("Largest: {}", self.first);↵
} else {↵
println!("Largest: {}", self.second);↵
}↵
}↵
}↵
↵
impl<T: Clone> Pair<T> {↵
fn swap(&self) -> Pair<T> {↵
Pair {↵
first: self.second.clone(),↵
second: self.first.clone(),↵
}↵
}↵
}↵
↵
fn main() {↵
let p1 = Pair::new(5, 10);↵
println!("Pair: {:?}", p1);↵
p1.cmp_display();↵
↵
let swapped = p1.swap();↵
println!("Swapped: {:?}", swapped);↵
↵
let p2 = Pair::new("hello", "world");↵
p2.cmp_display();↵
}