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, 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,
}
}
// --------------------