12: Add solution to Rust track exercise "Space Age".

[?]
9Zb2bmkejrNknawUtr3MKvVstZkVDR8x8ritfgZXKrky
Dec 23, 2021, 5:34 PM
44WIYRRYXHTRYJGD3ISP4HWTYOTHO7TA4HG56OWFUVS7ESUTGKFAC

Dependencies

  • [2] VXRUG632 11: Add Rust track exercise "Space Age".

Change contents

  • replacement in rust/space-age/src/lib.rs at line 5
    [2.1780][2.1780:1801]()
    pub struct Duration;
    [2.1780]
    [2.1801]
    pub struct Duration {
    seconds: f64,
    }
  • replacement in rust/space-age/src/lib.rs at line 10
    [2.1832][2.1832:1924]()
    fn from(s: u64) -> Self {
    unimplemented!("s, measured in seconds: {}", s)
    }
    [2.1832]
    [2.1924]
    fn from(s: u64) -> Self {
    Duration { seconds: s as f64 }
    }
  • replacement in rust/space-age/src/lib.rs at line 16
    [2.1946][2.1946:2142]()
    fn years_during(d: &Duration) -> f64 {
    unimplemented!(
    "convert a duration ({:?}) to the number of years on this planet for that duration",
    d,
    );
    }
    [2.1946]
    [2.2142]
    fn years_during(d: &Duration) -> f64;
  • replacement in rust/space-age/src/lib.rs at line 19
    [2.2145][2.2145:2296]()
    pub struct Mercury;
    pub struct Venus;
    pub struct Earth;
    pub struct Mars;
    pub struct Jupiter;
    pub struct Saturn;
    pub struct Uranus;
    pub struct Neptune;
    [2.2145]
    [2.2296]
    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
    }
    }
    )*};
    }
  • replacement in rust/space-age/src/lib.rs at line 30
    [2.2297][2.2297:2504]()
    impl Planet for Mercury {}
    impl Planet for Venus {}
    impl Planet for Earth {}
    impl Planet for Mars {}
    impl Planet for Jupiter {}
    impl Planet for Saturn {}
    impl Planet for Uranus {}
    impl Planet for Neptune {}
    [2.2297]
    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
    }