#[derive(Debug)]↵
struct Celsius(f64);↵
↵
#[derive(Debug)]↵
struct Fahrenheit(f64);↵
↵
#[derive(Debug)]↵
struct Kelvin(f64);↵
↵
impl From<Celsius> for Fahrenheit {↵
fn from(c: Celsius) -> Self {↵
Fahrenheit(c.0 * 9.0 / 5.0 + 32.0)↵
}↵
}↵
↵
impl From<Celsius> for Kelvin {↵
fn from(c: Celsius) -> Self {↵
Kelvin(c.0 + 273.15)↵
}↵
}↵
↵
impl From<Fahrenheit> for Celsius {↵
fn from(f: Fahrenheit) -> Self {↵
Celsius((f.0 - 32.0) * 5.0 / 9.0)↵
}↵
}↵
↵
fn print_temperature<T: std::fmt::Debug>(temp: T) {↵
println!("Temperature: {:?}", temp);↵
}↵
↵
fn main() {↵
let c = Celsius(100.0);↵
println!("Celsius: {:?}", c);↵
↵
let f: Fahrenheit = c.into();↵
print_temperature(&f);↵
↵
let c2 = Celsius(0.0);↵
let k = Kelvin::from(c2);↵
print_temperature(&k);↵
↵
let f2 = Fahrenheit(98.6);↵
let c3: Celsius = f2.into();↵
print_temperature(&c3);↵
}