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"
|
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]
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|
||||||
|
|||||||
@@ -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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -134,14 +134,14 @@ mod tests {
|
|||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_year_too_low() {
|
fn test_year_too_low() {
|
||||||
disable_panic_stack_trace();
|
disable_panic_stack_trace();
|
||||||
let _ = Hollidays::new(1000);
|
let _ = Hollidays::new(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_year_too_high() {
|
fn test_year_too_high() {
|
||||||
disable_panic_stack_trace();
|
disable_panic_stack_trace();
|
||||||
let _ = Hollidays::new(9999);
|
let _ = Hollidays::new(9999);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable_panic_stack_trace() {
|
fn disable_panic_stack_trace() {
|
||||||
|
|||||||
11
src/lib.rs
11
src/lib.rs
@@ -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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/main.rs
11
src/main.rs
@@ -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,23 +66,22 @@ 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() {
|
||||||
eprintln!("Failed to save to cache with: {:?}", e);
|
eprintln!("Failed to save to cache with: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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(¤cy);
|
header_description.replace_eur(currency);
|
||||||
let error_occured = change_perspective(&mut parsed, ¤cy).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;
|
||||||
|
|||||||
@@ -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(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ impl<'a> TableGet for TableRef<'a> {
|
|||||||
fn get_width(&self) -> usize {
|
fn get_width(&self) -> usize {
|
||||||
self.width
|
self.width
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_left_offset(&self) -> usize {
|
fn get_left_offset(&self) -> usize {
|
||||||
self.left_offset
|
self.left_offset
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user