diff --git a/Cargo.toml b/Cargo.toml index f7621f4..168b50b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 "] 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] diff --git a/src/cache/cache.rs b/src/caching/cache.rs similarity index 100% rename from src/cache/cache.rs rename to src/caching/cache.rs diff --git a/src/cache/cache_line.rs b/src/caching/cache_line.rs similarity index 100% rename from src/cache/cache_line.rs rename to src/caching/cache_line.rs diff --git a/src/cache/mod.rs b/src/caching/mod.rs similarity index 100% rename from src/cache/mod.rs rename to src/caching/mod.rs diff --git a/src/cli/cli_t.rs b/src/cli/cli_t.rs index a52e9b0..26419f8 100644 --- a/src/cli/cli_t.rs +++ b/src/cli/cli_t.rs @@ -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, diff --git a/src/cli/sort_by.rs b/src/cli/sort_by.rs index 3086333..4fa7818 100644 --- a/src/cli/sort_by.rs +++ b/src/cli/sort_by.rs @@ -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), } } diff --git a/src/header_description.rs b/src/header_description.rs index 6830cf3..0b40a10 100644 --- a/src/header_description.rs +++ b/src/header_description.rs @@ -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 { diff --git a/src/holiday.rs b/src/holiday.rs index 3c9a63c..0df16c6 100644 --- a/src/holiday.rs +++ b/src/holiday.rs @@ -134,14 +134,14 @@ mod tests { #[should_panic] fn test_year_too_low() { disable_panic_stack_trace(); - let _ = Hollidays::new(1000); + let _ = Hollidays::new(1000); } #[test] #[should_panic] fn test_year_too_high() { disable_panic_stack_trace(); - let _ = Hollidays::new(9999); + let _ = Hollidays::new(9999); } fn disable_panic_stack_trace() { diff --git a/src/lib.rs b/src/lib.rs index 9c4abd3..63a62e6 100644 --- a/src/lib.rs +++ b/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"; } } diff --git a/src/main.rs b/src/main.rs index e352130..3f6fc8b 100644 --- a/src/main.rs +++ b/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; diff --git a/src/parsing.rs b/src/parsing.rs index 4545c76..2e0e361 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -68,12 +68,11 @@ pub fn parse(xml: &str) -> anyhow::Result> { *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::()?; current_rates.insert(c, r); } - } Ok(()) } diff --git a/src/table/mod.rs b/src/table/mod.rs index 9167d4f..89f8b04 100644 --- a/src/table/mod.rs +++ b/src/table/mod.rs @@ -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; - diff --git a/src/table/table_ref.rs b/src/table/table_ref.rs index b7b13ac..7f49ac8 100644 --- a/src/table/table_ref.rs +++ b/src/table/table_ref.rs @@ -78,7 +78,7 @@ impl<'a> TableGet for TableRef<'a> { fn get_width(&self) -> usize { self.width } - + fn get_left_offset(&self) -> usize { self.left_offset }