universal_constants 0.0.1

Physical and mathematical constants that are generally considered to be universally constant.
Documentation
//! Unit conversions as constant multiplication factors.

/// Distance conversions.
pub mod distance {
    /// Feet to meters.
    pub const FEET_TO_METERS: f64 = 0.3048;

    /// Feet to nautical miles.
    pub const FEET_TO_NMI: f64 = 0.3048 / 1852.0;

    /// Meters to feet.
    pub const METERS_TO_FEET: f64 = 1.0 / 0.3048;

    /// Meters to nautical miles.
    pub const METERS_TO_NMI: f64 = 1.0 / 1852.0;

    /// Nautical miles to feet.
    pub const NMI_TO_FEET: f64 = 1852.0 / 0.3048;

    /// Nautical miles to meters.
    pub const NMI_TO_METERS: f64 = 1852.0;
}

/// Time conversions.
pub mod time {
    /// Days to hours.
    pub const DAYS_TO_HOURS: f64 = 24.0;

    /// Days to minutes.
    pub const DAYS_TO_MINUTES: f64 = 1440.0;

    /// Days to seconds.
    pub const DAYS_TO_SECONDS: f64 = 86400.0;

    /// Hours to days.
    pub const HOURS_TO_DAYS: f64 = 1.0 / 24.0;

    /// Hours to seconds.
    pub const HOURS_TO_SECONDS: f64 = 3600.0;

    /// Hours to minutes.
    pub const HOURS_TO_MINUTES: f64 = 60.0;

    /// Minutes to days.
    pub const MINUTES_TO_DAYS: f64 = 1.0 / 1440.0;

    /// Minutes to hours.
    pub const MINUTES_TO_HOURS: f64 = 1.0 / 60.0;

    /// Minutes to seconds.
    pub const MINUTES_TO_SECONDS: f64 = 60.0;

    /// Seconds to days.
    pub const SECONDS_TO_DAYS: f64 = 1.0 / 86400.0;

    /// Seconds to hours.
    pub const SECONDS_TO_HOURS: f64 = 1.0 / 3600.0;

    /// Seconds to minutes.
    pub const SECONDS_TO_MINUTES: f64 = 1.0 / 60.0;
}

#[cfg(test)]
mod tests {
    use crate::conversions::{distance, time};

    #[test]
    fn distance_tests() {
        assert_eq!(distance::FEET_TO_METERS, 0.3048);
        assert_eq!(distance::FEET_TO_NMI, 0.3048 / 1852.0);
        assert_eq!(distance::METERS_TO_FEET, 1.0 / 0.3048);
        assert_eq!(distance::METERS_TO_NMI, 1.0 / 1852.0);
        assert_eq!(distance::NMI_TO_FEET, 1852.0 / 0.3048);
        assert_eq!(distance::NMI_TO_METERS, 1852.0);
    }

    #[test]
    fn time_tests() {
        assert_eq!(time::DAYS_TO_HOURS, 24.0);
        assert_eq!(time::DAYS_TO_MINUTES, 1440.0);
        assert_eq!(time::DAYS_TO_SECONDS, 86400.0);
        assert_eq!(time::HOURS_TO_DAYS, 1.0 / 24.0);
        assert_eq!(time::HOURS_TO_SECONDS, 3600.0);
        assert_eq!(time::HOURS_TO_MINUTES, 60.0);
        assert_eq!(time::MINUTES_TO_DAYS, 1.0 / 1440.0);
        assert_eq!(time::MINUTES_TO_HOURS, 1.0 / 60.0);
        assert_eq!(time::MINUTES_TO_SECONDS, 60.0);
        assert_eq!(time::SECONDS_TO_DAYS, 1.0 / 86400.0);
        assert_eq!(time::SECONDS_TO_HOURS, 1.0 / 3600.0);
        assert_eq!(time::SECONDS_TO_MINUTES, 1.0 / 60.0);
    }
}