Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ update Rust crate optional_struct to 0.5 #281

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ clap = { version = "4.5", default-features = false, features = [
directories = "5.0"
dialoguer = { version = "0.11", default-features = false }
futures = "0.3"
optional_struct = "0.3"
optional_struct = "0.5"
regex = { version = "1.10" }
reqwest = { version = "0.12", features = ["json"] }
ron = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use dialoguer::console::style;
use directories::ProjectDirs;
use optional_struct::{optional_struct, Applyable};
use optional_struct::{optional_struct, Applicable};
use ron::{
extensions::Extensions,
ser::{to_string_pretty, PrettyConfig},
Expand Down
2 changes: 1 addition & 1 deletion src/modules/display/graph.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use optional_struct::{optional_struct, Applyable};
use optional_struct::optional_struct;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;

Expand Down
2 changes: 1 addition & 1 deletion src/modules/display/gui_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dialoguer::console::{style, StyledObject};
use optional_struct::{optional_struct, Applyable};
use optional_struct::{optional_struct, Applicable};
use serde::{Deserialize, Serialize};

use crate::modules::display::{
Expand Down
4 changes: 2 additions & 2 deletions src/modules/display/historical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl HistoricalWeather {

// Helpers
let weather = &product.historical_weather.as_ref().unwrap()[date];
let weather_daily = weather.daily.as_ref().unwrap();
let weather_daily = &weather.daily;
let weather_daily_units = weather.daily_units.as_ref().unwrap();
let lang = &params.config.language;
// Times
Expand Down Expand Up @@ -183,7 +183,7 @@ impl HistoricalWeather {
let sunrise = format!(" {sunrise}");
let sunset = format!(" {sunset}");
let wmo_code = WeatherCode::resolve(
weather.daily.as_ref().unwrap().weathercode.as_ref().unwrap()[0],
weather.daily.weathercode.as_ref().unwrap()[0],
false,
&params.texts.weather.weather_code,
)?;
Expand Down
10 changes: 5 additions & 5 deletions src/modules/display/hourly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,25 @@ impl HourlyForecast {
// Therefore we'll extend the values by 1. For this we simply use the last value of the array twice.
let (mut temps, mut codes, mut prec);
let temperatures = {
temps = weather.hourly.as_ref().unwrap().temperature_2m.as_ref().unwrap()[0..].to_vec();
temps = weather.hourly.temperature_2m.as_ref().unwrap()[0..].to_vec();
temps.push(temps[temps.len() - 1]);
&temps
};
let weather_codes = {
codes = weather.hourly.as_ref().unwrap().weathercode.as_ref().unwrap()[0..].to_vec();
codes = weather.hourly.weathercode.as_ref().unwrap()[0..].to_vec();
codes.push(codes[codes.len() - 1]);
&codes
};
let sunrise_sunset = (
weather.daily.as_ref().unwrap().sunrise.as_ref().unwrap()[0][11..13]
weather.daily.sunrise.as_ref().unwrap()[0][11..13]
.parse::<usize>()
.unwrap_or_default(),
weather.daily.as_ref().unwrap().sunset.as_ref().unwrap()[0][11..13]
weather.daily.sunset.as_ref().unwrap()[0][11..13]
.parse::<usize>()
.unwrap_or_default(),
);
let precipitation = {
prec = weather.hourly.as_ref().unwrap().precipitation.as_ref().unwrap()[0..].to_vec();
prec = weather.hourly.precipitation.as_ref().unwrap()[0..].to_vec();
prec.push(prec[prec.len() - 1]);
prec.iter().map(|x| x.ceil() as u8).collect::<Vec<u8>>()
};
Expand Down
2 changes: 1 addition & 1 deletion src/modules/localization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{Context, Result};
use chrono::{Local, NaiveDate};
use directories::ProjectDirs;
use futures::{stream::FuturesOrdered, TryStreamExt};
use optional_struct::{optional_struct, Applyable};
use optional_struct::{optional_struct, Applicable};
use reqwest::Url;
use serde::{Deserialize, Serialize};
use serde_json::Value;
Expand Down
8 changes: 2 additions & 6 deletions src/modules/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::HashSet;
use anyhow::{Context, Result};
use chrono::NaiveDate;
use dialoguer::{theme::ColorfulTheme, Confirm, Select};
use optional_struct::Applyable;

use super::{
args::{Cli, Forecast},
Expand Down Expand Up @@ -69,7 +68,7 @@ impl Params {
})
}

pub fn handle_next(mut self, args: Cli, mut config_file: Config) -> Result<()> {
pub fn handle_next(mut self, args: Cli, config_file: Config) -> Result<()> {
if !args.save && !config_file.address.is_empty() {
return Ok(());
}
Expand All @@ -79,13 +78,10 @@ impl Params {

if config_file.address.is_empty() {
// Prompt to save
self.config.apply_to(&mut config_file);
self.config = config_file;
self.save_prompt(&args.address.unwrap_or_default())?;
} else {
// Handle explicit save call
self.config.apply_to(&mut config_file);
config_file.store().context("Error saving config file.")?;
self.config.store().context("Error saving config file.")?;
self.texts.store(&config_file.language);
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/units.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use optional_struct::{optional_struct, Applyable};
use optional_struct::optional_struct;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use strum::VariantNames;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/weather.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{Context, Result};
use chrono::{Local, NaiveDate};
use optional_struct::{optional_struct, Applyable};
use optional_struct::{optional_struct, Applicable};
use serde::Deserialize;
use std::collections::{HashMap, HashSet};

Expand Down
Loading