#[derive(Debug)] pub struct Duration(f64); impl From for Duration { fn from(s: u64) -> Self { Self(s as f64) } } pub trait Planet { const EARTH_SECONDS: f64 = 31557600.; const SECONDS_IN_YEAR: f64; fn years_during(d: &Duration) -> f64 { d.0 / Self::SECONDS_IN_YEAR } } macro_rules! planets { ( $( $planet:ident -> $ratio:expr ),* ) => { $( pub struct $planet; impl Planet for $planet { const SECONDS_IN_YEAR: f64 = $ratio * Self::EARTH_SECONDS; } )* } } planets!( Mercury -> 0.2408467, Venus -> 0.61519726, Earth -> 1.0, Mars -> 1.8808158, Jupiter -> 11.862615, Saturn -> 29.447498, Uranus -> 84.016846, Neptune -> 164.79132 );