Bump MSRV and cleanup with clippy

This commit is contained in:
2025-12-17 22:20:31 +01:00
parent f388c31594
commit 364875a84e
13 changed files with 27 additions and 26 deletions

View File

@@ -2,7 +2,7 @@
name = "ecb-rates" name = "ecb-rates"
description = "Query exchange rates from the European Central Bank (ECB)" description = "Query exchange rates from the European Central Bank (ECB)"
version = "1.0.1" version = "1.0.1"
edition = "2021" edition = "2024"
authors = ["Love Billenius <lovebillenius@disroot.org>"] authors = ["Love Billenius <lovebillenius@disroot.org>"]
license = "Zlib" license = "Zlib"
keywords = [ keywords = [
@@ -13,7 +13,7 @@ keywords = [
"rates", "rates",
] ]
repository = "https://github.com/lov3b/ecb-rates" repository = "https://github.com/lov3b/ecb-rates"
rust-version = "1.83" rust-version = "1.92"
categories = ["finance", "command-line-utilities"] categories = ["finance", "command-line-utilities"]
[profile.release] [profile.release]

View File

@@ -1,11 +1,10 @@
use clap::{arg, Parser, ValueEnum}; use clap::{Parser, ValueEnum};
use smol_str::SmolStr; use smol_str::SmolStr;
use super::{ShowDays, SortBy}; use super::{ShowDays, SortBy};
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
#[command(author, version, about)] #[command(author, version, about)]
pub struct Cli { pub struct Cli {
/// Which currencies do you want to fetch rates for? /// Which currencies do you want to fetch rates for?
#[arg(long = "currencies", short = 'c')] #[arg(long = "currencies", short = 'c')]
@@ -42,7 +41,7 @@ pub struct Cli {
#[arg(long = "invert", short = 'i')] #[arg(long = "invert", short = 'i')]
pub should_invert: bool, pub should_invert: bool,
//// Max decimals to keep in price. /// Max decimals to keep in price.
#[arg(long = "max-decimals", short = 'd', default_value_t = 5)] #[arg(long = "max-decimals", short = 'd', default_value_t = 5)]
pub max_decimals: u8, pub max_decimals: u8,

View File

@@ -9,7 +9,7 @@ pub enum SortBy {
impl SortBy { impl SortBy {
pub fn get_comparer(&self) -> fn(&(&str, f64), &(&str, f64)) -> std::cmp::Ordering { pub fn get_comparer(&self) -> fn(&(&str, f64), &(&str, f64)) -> std::cmp::Ordering {
match self { match self {
Self::Currency => |a, b| a.0.cmp(&b.0), Self::Currency => |a, b| a.0.cmp(b.0),
Self::Rate => |a, b| a.1.total_cmp(&b.1), Self::Rate => |a, b| a.1.total_cmp(&b.1),
} }
} }

View File

@@ -7,6 +7,12 @@ pub struct HeaderDescription<'a> {
header_description: [&'a str; 2], header_description: [&'a str; 2],
} }
impl<'a> Default for HeaderDescription<'a> {
fn default() -> Self {
Self::new()
}
}
impl<'a> HeaderDescription<'a> { impl<'a> HeaderDescription<'a> {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {

View File

@@ -1,4 +1,4 @@
pub mod cache; pub mod caching;
pub mod cli; pub mod cli;
mod header_description; mod header_description;
mod holiday; mod holiday;
@@ -13,16 +13,15 @@ pub use header_description::HeaderDescription;
pub use holiday::Hollidays; pub use holiday::Hollidays;
pub use view::View; pub use view::View;
const APP_NAME: &'static str = "ECB-rates"; const APP_NAME: &str = "ECB-rates";
const DEFAULT_WIDTH: usize = 20; const DEFAULT_WIDTH: usize = 20;
pub mod ecb_url { pub mod ecb_url {
pub const TODAY: &'static str = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; pub const TODAY: &str = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
pub mod hist { pub mod hist {
pub const DAYS_ALL: &'static str = pub const DAYS_ALL: &str = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml";
"https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml"; pub const DAYS_90: &str =
pub const DAYS_90: &'static str =
"https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml"; "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml";
} }
} }

View File

@@ -1,5 +1,5 @@
use clap::Parser as _; use clap::Parser as _;
use ecb_rates::cache::{Cache, CacheLine}; use ecb_rates::caching::{Cache, CacheLine};
use ecb_rates::HeaderDescription; use ecb_rates::HeaderDescription;
use reqwest::{Client, IntoUrl}; use reqwest::{Client, IntoUrl};
use smol_str::StrExt; use smol_str::StrExt;
@@ -66,8 +66,8 @@ async fn main() -> ExitCode {
}, },
); );
if not_equal_cache { if not_equal_cache
if let Some(cache_safe) = cache.as_mut() { && let Some(cache_safe) = cache.as_mut() {
let cache_line = CacheLine::new(parsed.clone()); let cache_line = CacheLine::new(parsed.clone());
cache_safe.set_cache_line(cache_line); cache_safe.set_cache_line(cache_line);
if let Err(e) = cache_safe.save() { if let Err(e) = cache_safe.save() {
@@ -75,14 +75,13 @@ async fn main() -> ExitCode {
} }
} }
} }
}
parsed parsed
}; };
cli.perspective = cli.perspective.map(|s| s.to_uppercase_smolstr()); cli.perspective = cli.perspective.map(|s| s.to_uppercase_smolstr());
if let Some(currency) = cli.perspective.as_ref() { if let Some(currency) = cli.perspective.as_ref() {
header_description.replace_eur(&currency); header_description.replace_eur(currency);
let error_occured = change_perspective(&mut parsed, &currency).is_none(); let error_occured = change_perspective(&mut parsed, currency).is_none();
if error_occured { if error_occured {
eprintln!("The currency wasn't in the data from the ECB!"); eprintln!("The currency wasn't in the data from the ECB!");
return ExitCode::FAILURE; return ExitCode::FAILURE;

View File

@@ -68,12 +68,11 @@ pub fn parse(xml: &str) -> anyhow::Result<Vec<ExchangeRateResult>> {
*inside_cube_time = true; *inside_cube_time = true;
} }
if *inside_cube_time { if *inside_cube_time
if let (Some(c), Some(r_str)) = (currency_attr, rate_attr) { && let (Some(c), Some(r_str)) = (currency_attr, rate_attr) {
let r = r_str.parse::<f64>()?; let r = r_str.parse::<f64>()?;
current_rates.insert(c, r); current_rates.insert(c, r);
} }
}
Ok(()) Ok(())
} }

View File

@@ -1,11 +1,10 @@
mod table_display;
mod table_getter; mod table_getter;
mod table_owned; mod table_owned;
mod table_ref; mod table_ref;
mod table_trait; mod table_trait;
mod table_display;
pub use table_getter::TableGet; pub use table_getter::TableGet;
pub use table_owned::Table; pub use table_owned::Table;
pub use table_ref::TableRef; pub use table_ref::TableRef;
pub use table_trait::TableTrait; pub use table_trait::TableTrait;