Skip to content

Commit 7ba27e6

Browse files
authored
Merge branch 'ttytm:main' into main
2 parents 0120646 + 767557f commit 7ba27e6

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

src/main.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ async fn main() -> Result<()> {
3030
async fn run(params: &Params) -> Result<Product> {
3131
let loc = Location::get(&params.config.address, &params.config.language).await?;
3232
let weather = Weather::get(loc.lat, loc.lon, &params.config.units).await?;
33-
let historical_weather = if params.historical_weather.is_empty() {
34-
None
35-
} else {
36-
Some(Weather::get_dates(&params.historical_weather, loc.lat, loc.lon, &params.config.units).await?)
37-
};
33+
let historical_weather =
34+
Weather::get_dates(&params.historical_weather, loc.lat, loc.lon, &params.config.units).await?;
3835

3936
Ok(Product {
40-
address: loc.name.to_string(),
37+
address: loc.name,
4138
weather,
4239
historical_weather,
4340
})

src/modules/display/historical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn prep(product: &Product, params: &Params, date: NaiveDate) -> Result<Vec<S
2424
let address = Product::trunc_address(product.address.clone(), 60);
2525

2626
// Helpers
27-
let weather = &product.historical_weather.as_ref().unwrap()[&date];
27+
let weather = &product.historical_weather[&date];
2828
let weather_daily_units = weather.daily_units.as_ref().unwrap();
2929
let lang = &params.config.language;
3030
// Times

src/modules/display/product.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::{current, day, gui_config::ConfigurableColor, historical, week};
1515
pub struct Product<'a> {
1616
pub address: String,
1717
pub weather: Weather,
18-
pub historical_weather: Option<HashMap<&'a NaiveDate, OptionalWeather>>,
18+
pub historical_weather: HashMap<&'a NaiveDate, OptionalWeather>,
1919
}
2020

2121
pub const MIN_WIDTH: usize = 34;

src/modules/display/utils.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ pub fn style_number(mut num: i32, sub: bool) -> String {
4141
const SUPERSCRIPT_DIGITS: [char; 10] = ['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹'];
4242
const SUBSCRIPT_DIGITS: [char; 10] = ['₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉'];
4343

44+
let digits = if sub { SUBSCRIPT_DIGITS } else { SUPERSCRIPT_DIGITS };
45+
4446
let mut result = String::new();
4547

4648
if num == 0 {
47-
result.push(if sub { SUBSCRIPT_DIGITS[0] } else { SUPERSCRIPT_DIGITS[0] });
49+
result.push(digits[0]);
4850
return result;
4951
}
5052

@@ -61,11 +63,7 @@ pub fn style_number(mut num: i32, sub: bool) -> String {
6163
power_of_ten /= 10;
6264
if digit != 0 || started {
6365
started = true;
64-
result.push(if sub {
65-
SUBSCRIPT_DIGITS[digit as usize]
66-
} else {
67-
SUPERSCRIPT_DIGITS[digit as usize]
68-
});
66+
result.push(digits[digit as usize])
6967
}
7068
}
7169

@@ -79,7 +77,7 @@ pub mod common_tests {
7977
use crate::modules::localization;
8078
use crate::modules::params::Params;
8179
use crate::modules::weather;
82-
use std::collections::HashSet;
80+
use std::collections::{HashMap, HashSet};
8381
use std::sync::OnceLock;
8482

8583
pub static TEST_PRODUCT: OnceLock<Product> = OnceLock::new();
@@ -242,7 +240,7 @@ pub mod common_tests {
242240
precipitation_sum: None,
243241
},
244242
},
245-
historical_weather: None,
243+
historical_weather: HashMap::new(),
246244
}
247245
}
248246

0 commit comments

Comments
 (0)