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

View File

@@ -1,11 +1,10 @@
use clap::{arg, Parser, ValueEnum};
use clap::{Parser, ValueEnum};
use smol_str::SmolStr;
use super::{ShowDays, SortBy};
#[derive(Debug, Parser)]
#[command(author, version, about)]
pub struct Cli {
/// Which currencies do you want to fetch rates for?
#[arg(long = "currencies", short = 'c')]
@@ -42,7 +41,7 @@ pub struct Cli {
#[arg(long = "invert", short = 'i')]
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)]
pub max_decimals: u8,

View File

@@ -9,7 +9,7 @@ pub enum SortBy {
impl SortBy {
pub fn get_comparer(&self) -> fn(&(&str, f64), &(&str, f64)) -> std::cmp::Ordering {
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),
}
}

View File

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

View File

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

View File

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

View File

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

View File

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