lib.rs
// The code below is a stub. Just enough to satisfy the compiler.
// In order to pass the tests you can add-to or change any of this code.
#[derive(Debug)]
pub struct Duration {
seconds: f64,
}
impl From<u64> for Duration {
fn from(s: u64) -> Self {
Duration { seconds: s as f64 }
}
}
pub trait Planet {
fn years_during(d: &Duration) -> f64;
}
macro_rules! impl_planets {
($($planet:ident : $period:literal),*) => {$(
pub struct $planet;
impl Planet for $planet {
fn years_during(d: &Duration) -> f64 {
d.seconds / 31557600.0 / $period
}
}
)*};
}
impl_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
}