Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const EARTH_YEAR_SECS: f64 = 31557600.0;
- #[derive(Debug)]
- pub struct Duration {
- secs: f64,
- }
- impl From<u64> for Duration {
- fn from(s: u64) -> Self {
- Duration { secs: s as f64 }
- }
- }
- impl From<f64> for Duration {
- fn from(s: f64) -> Self {
- Duration { secs: s }
- }
- }
- pub trait Planet {
- fn orbit_duration() -> Duration;
- fn years_during(d: &Duration) -> f64 {
- d.secs / Self::orbit_duration().secs
- }
- }
- pub struct Mercury;
- pub struct Venus;
- pub struct Earth;
- pub struct Mars;
- pub struct Jupiter;
- pub struct Saturn;
- pub struct Uranus;
- pub struct Neptune;
- impl Planet for Mercury {
- fn orbit_duration() -> Duration {
- Duration::from(0.2408467 * EARTH_YEAR_SECS)
- }
- }
- impl Planet for Venus {
- fn orbit_duration() -> Duration {
- Duration::from(0.61519726 * EARTH_YEAR_SECS)
- }
- }
- impl Planet for Earth {
- fn orbit_duration() -> Duration {
- Duration::from(EARTH_YEAR_SECS)
- }
- }
- impl Planet for Mars {
- fn orbit_duration() -> Duration {
- Duration::from(1.8808158 * EARTH_YEAR_SECS)
- }
- }
- impl Planet for Jupiter {
- fn orbit_duration() -> Duration {
- Duration::from(11.862615 * EARTH_YEAR_SECS)
- }
- }
- impl Planet for Saturn {
- fn orbit_duration() -> Duration {
- Duration::from(29.447498 * EARTH_YEAR_SECS)
- }
- }
- impl Planet for Uranus {
- fn orbit_duration() -> Duration {
- Duration::from(84.016846 * EARTH_YEAR_SECS)
- }
- }
- impl Planet for Neptune {
- fn orbit_duration() -> Duration {
- Duration::from(164.79132 * EARTH_YEAR_SECS)
- }
- }
Add Comment
Please, Sign In to add comment