Proper use of enum

This commit is contained in:
Mahesh Asolkar 2025-05-03 14:35:58 -07:00
parent 928a0547d3
commit b3a322f694

View File

@ -30,7 +30,7 @@ impl fmt::Display for TemperatureUnits {
#[command(about = "Gets weather info for the bar")] #[command(about = "Gets weather info for the bar")]
#[command(about, long_about = "Get weather information for the station indicated #[command(about, long_about = "Get weather information for the station indicated
by the --station argument. Imperial units by default. by the --station argument. Imperial units by default.
Use --metirc to use metric units")] Use --metric to use metric units")]
struct CommandlineArgs { struct CommandlineArgs {
/// Name of the weather station /// Name of the weather station
#[arg(short, long, default_value = "khio")] #[arg(short, long, default_value = "khio")]
@ -141,12 +141,10 @@ impl BarWeather {
// -------------------- // --------------------
fn check_options(&self) -> bool { fn check_options(&self) -> bool {
let mut all_good = true; let all_good = true;
if ! ((self.opts.units == TemperatureUnits::Metric) // If there are option checks to be added, make all_good a
|| (self.opts.units == TemperatureUnits::Imperial)) { // mutable var and update its status
all_good &= false;
}
return all_good; return all_good;
} }
@ -156,8 +154,10 @@ impl BarWeather {
let deg_c :f32 = v["features"][0]["properties"]["temperature"]["value"] let deg_c :f32 = v["features"][0]["properties"]["temperature"]["value"]
.to_string().parse().unwrap(); .to_string().parse().unwrap();
return if self.opts.units == TemperatureUnits::Metric { deg_c } match self.opts.units {
else { (deg_c * 9.0 / 5.0) + 32.0}; TemperatureUnits::Metric => return deg_c,
TemperatureUnits::Imperial => return (deg_c * 9.0 / 5.0) + 32.0,
}
} }
// -------------------- // --------------------