From b3a322f694391e073550235d567021ee0d9dba6d Mon Sep 17 00:00:00 2001 From: Mahesh Asolkar Date: Sat, 3 May 2025 14:35:58 -0700 Subject: [PATCH] Proper use of enum --- src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 257cf16..531f7d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ impl fmt::Display for TemperatureUnits { #[command(about = "Gets weather info for the bar")] #[command(about, long_about = "Get weather information for the station indicated by the --station argument. Imperial units by default. -Use --metirc to use metric units")] +Use --metric to use metric units")] struct CommandlineArgs { /// Name of the weather station #[arg(short, long, default_value = "khio")] @@ -141,12 +141,10 @@ impl BarWeather { // -------------------- fn check_options(&self) -> bool { - let mut all_good = true; + let all_good = true; - if ! ((self.opts.units == TemperatureUnits::Metric) - || (self.opts.units == TemperatureUnits::Imperial)) { - all_good &= false; - } + // If there are option checks to be added, make all_good a + // mutable var and update its status return all_good; } @@ -156,8 +154,10 @@ impl BarWeather { let deg_c :f32 = v["features"][0]["properties"]["temperature"]["value"] .to_string().parse().unwrap(); - return if self.opts.units == TemperatureUnits::Metric { deg_c } - else { (deg_c * 9.0 / 5.0) + 32.0}; + match self.opts.units { + TemperatureUnits::Metric => return deg_c, + TemperatureUnits::Imperial => return (deg_c * 9.0 / 5.0) + 32.0, + } } // --------------------