From 2d9995777115f3210197893a026bee74f3fd20a3 Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Tue, 7 Jan 2025 17:21:46 +0100 Subject: [PATCH] Use anyhow --- src/main.rs | 4 ++-- src/parsing.rs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9d011ca..af5e5b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,14 @@ use clap::Parser as _; use ecb_rates::cache::Cache; use reqwest::{Client, IntoUrl}; -use std::{borrow::BorrowMut, collections::HashMap, error::Error, process::ExitCode}; +use std::{borrow::BorrowMut, collections::HashMap, process::ExitCode}; use ecb_rates::cli::{Cli, FormatOption}; use ecb_rates::models::ExchangeRateResult; use ecb_rates::parsing::parse; use ecb_rates::table::Table; -async fn get_and_parse(url: impl IntoUrl) -> Result, Box> { +async fn get_and_parse(url: impl IntoUrl) -> anyhow::Result> { let client = Client::new(); let xml_content = client.get(url).send().await?.text().await?; parse(&xml_content) diff --git a/src/parsing.rs b/src/parsing.rs index bb88a84..daa6cac 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -1,12 +1,11 @@ use std::collections::HashMap; -use std::error::Error; use quick_xml::events::Event; use quick_xml::Reader; use crate::models::ExchangeRateResult; -pub fn parse(xml: &str) -> Result, Box> { +pub fn parse(xml: &str) -> anyhow::Result> { let mut reader = Reader::from_str(xml); reader.config_mut().trim_text(true); @@ -21,7 +20,7 @@ pub fn parse(xml: &str) -> Result, Box> { inside_cube_time: &mut bool, current_rates: &mut HashMap, results: &mut Vec, - ) -> Result<(), Box> { + ) -> anyhow::Result<()> { if e.name().local_name().as_ref() != b"Cube" { return Ok(()); }