mirror of
https://github.com/lov3b/ecb-rates.git
synced 2025-12-20 03:10:38 +01:00
Bump MSRV and cleanup with clippy
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
11
src/lib.rs
11
src/lib.rs
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@@ -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,23 +66,22 @@ 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() {
|
||||
eprintln!("Failed to save to cache with: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parsed
|
||||
};
|
||||
|
||||
cli.perspective = cli.perspective.map(|s| s.to_uppercase_smolstr());
|
||||
if let Some(currency) = cli.perspective.as_ref() {
|
||||
header_description.replace_eur(¤cy);
|
||||
let error_occured = change_perspective(&mut parsed, ¤cy).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;
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user