mirror of
				https://github.com/lov3b/ecb-rates.git
				synced 2025-11-03 23:00:21 +01:00 
			
		
		
		
	Use anyhow
This commit is contained in:
		@@ -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<Vec<ExchangeRateResult>, Box<dyn Error>> {
 | 
			
		||||
async fn get_and_parse(url: impl IntoUrl) -> anyhow::Result<Vec<ExchangeRateResult>> {
 | 
			
		||||
    let client = Client::new();
 | 
			
		||||
    let xml_content = client.get(url).send().await?.text().await?;
 | 
			
		||||
    parse(&xml_content)
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Vec<ExchangeRateResult>, Box<dyn Error>> {
 | 
			
		||||
pub fn parse(xml: &str) -> anyhow::Result<Vec<ExchangeRateResult>> {
 | 
			
		||||
    let mut reader = Reader::from_str(xml);
 | 
			
		||||
    reader.config_mut().trim_text(true);
 | 
			
		||||
 | 
			
		||||
@@ -21,7 +20,7 @@ pub fn parse(xml: &str) -> Result<Vec<ExchangeRateResult>, Box<dyn Error>> {
 | 
			
		||||
        inside_cube_time: &mut bool,
 | 
			
		||||
        current_rates: &mut HashMap<String, f64>,
 | 
			
		||||
        results: &mut Vec<ExchangeRateResult>,
 | 
			
		||||
    ) -> Result<(), Box<dyn Error>> {
 | 
			
		||||
    ) -> anyhow::Result<()> {
 | 
			
		||||
        if e.name().local_name().as_ref() != b"Cube" {
 | 
			
		||||
            return Ok(());
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user