//! # Conversation //! Conversion for (distance/length, weight, volume) /// # Example /// ``` /// let distance_before = 5000000.0; /// let unit_before = 2; /// let unit_to_convert = 4; /// let conversion = match unit_to_convert { /// 1 => crates_conv_len_wt_vol::Distance::to_mm(unit_before, distance_before), /// 2 => crates_conv_len_wt_vol::Distance::to_cm(unit_before, distance_before), /// 3 => crates_conv_len_wt_vol::Distance::to_m(unit_before, distance_before), /// 4 => crates_conv_len_wt_vol::Distance::to_km(unit_before, distance_before), /// 5 => crates_conv_len_wt_vol::Distance::to_mile(unit_before, distance_before), /// _ => 0.0, /// }; /// if conversion == 0.0 { /// }else{ /// assert_eq!(50.0, conversion); /// } /// ``` pub mod Distance { pub fn to_mm(uni: i32, val: f64) -> f64 { match uni { 1 => val * 10.0, // cm 2 => val * 1000.0, // m 3 => val * 1000000.0, // km 4 => val * 1609344.0, // mile _ => 0.0, } } pub fn to_cm(uni: i32, val: f64) -> f64 { match uni { 1 => val / 10.0, // mm 2 => val * 100.0, // m 3 => val * 100000.0, // km 4 => val * 160934.4, // mile _ => 0.0, } } pub fn to_m(uni: i32, val: f64) -> f64 { match uni { 1 => val / 1000.0, // mm 2 => val / 100.0, // cm 3 => val * 1000.0, // km 4 => val * 1609.344, // mile _ => 0.0, } } pub fn to_km(uni: i32, val: f64) -> f64 { match uni { 1 => val / 1000000.0, // mm 2 => val / 100000.0, // cm 3 => val / 1000.0, // m 4 => val * 1.609344, // mile _ => 0.0, } } pub fn to_mile(uni: i32, val: f64) -> f64 { match uni { 1 => val / 6213712000000.0, // mm 2 => val / 621371200000.0, // cm 3 => val / 6213712000.0, // m 4 => val * 0.6213712, // km _ => 0.0, } } } /// # Examples /// ``` /// let weight_before = 6000.0; /// let unit_before = 2; /// let unit_to_convert = 3; /// let conversion = match unit_to_convert { /// 1 => crates_conv_len_wt_vol::Weight::to_mg(unit_before, weight_before), /// 2 => crates_conv_len_wt_vol::Weight::to_g(unit_before, weight_before), /// 3 => crates_conv_len_wt_vol::Weight::to_kg(unit_before, weight_before), /// 4 => crates_conv_len_wt_vol::Weight::to_ton(unit_before, weight_before), /// _ => 0.0, /// }; /// if conversion == 0.0 { /// }else{ /// assert_eq!(6.0, conversion); /// } /// ``` pub mod Weight { pub fn to_mg(uni: i32, val: f64) -> f64 { match uni { 1 => val * 1000.0, // g 2 => val * 1000000.0, // kg 3 => val * 907184740.0, // ton _ => 0.0, } } pub fn to_g(uni: i32, val: f64) -> f64 { match uni { 1 => val / 1000.0, // mg 2 => val * 1000.0, // kg 3 => val * 907184.74, // ton _ => 0.0, } } pub fn to_kg(uni: i32, val: f64) -> f64 { match uni { 1 => val / 1000000.0, // mg 2 => val / 1000.0, // g 3 => val * 907.1847, // ton _ => 0.0, } } pub fn to_ton(uni: i32, val: f64) -> f64 { match uni { 1 => val / 907184740.0, // mg 2 => val / 907184.74, // g 3 => val / 907.1847, // kg _ => 0.0, } } } /// # Example /// ``` /// let volume_before = 5000.0; /// let unit_before = 1; /// let unit_to_convert = 2; /// let conversion = match unit_to_convert { /// 1 => crates_conv_len_wt_vol::Volume::to_ml(unit_before, volume_before), // to mm /// 2 => crates_conv_len_wt_vol::Volume::to_l(unit_before, volume_before), // to cm /// 3 => crates_conv_len_wt_vol::Volume::to_gallon(unit_before, volume_before), // to mile /// _ => 0.0, /// }; /// assert_eq!(5.0, conversion); /// ``` pub mod Volume { pub fn to_ml(uni: i32, val: f64) -> f64 { match uni { 1 => val / 1000.0, // l 2 => val / 3785.4, // gallon _ => 0.0, } } pub fn to_l(uni: i32, val: f64) -> f64 { match uni { 1 => val / 1000.0, // ml 2 => val * 3.7854, // gallon _ => 0.0, } } pub fn to_gallon(uni: i32, val: f64) -> f64 { match uni { 1 => val * 3785.4, // ml 2 => val * 3.7854, // l _ => 0.0, } } }