From 4065b83a0d16eeec898fd1a91bf267752a494ee4 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 27 Nov 2022 22:19:43 +0100 Subject: [PATCH] Removed new type error --- .../psxcdgen_ex/src/config_reader/mod.rs | 2 +- .../psxcdgen_ex/src/config_reader/xml.rs | 32 ++----------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/Tools/psxcdgen_ex/src/config_reader/mod.rs b/src/Tools/psxcdgen_ex/src/config_reader/mod.rs index b635c56a..6f167dd5 100644 --- a/src/Tools/psxcdgen_ex/src/config_reader/mod.rs +++ b/src/Tools/psxcdgen_ex/src/config_reader/mod.rs @@ -1,4 +1,4 @@ -use super::{Error, ErrorString}; +use super::Error; use std::path::PathBuf; mod xml; diff --git a/src/Tools/psxcdgen_ex/src/config_reader/xml.rs b/src/Tools/psxcdgen_ex/src/config_reader/xml.rs index df2ababb..a50a412f 100644 --- a/src/Tools/psxcdgen_ex/src/config_reader/xml.rs +++ b/src/Tools/psxcdgen_ex/src/config_reader/xml.rs @@ -2,11 +2,11 @@ use std::path::PathBuf; use tool_helper::format_if_error; use crate::config_reader::Directory; -use super::{Configuration, ErrorString, File}; +use super::{Configuration, Error, File}; pub fn parse(xml: String) -> Result { let mut config = Configuration::new(); - let parser = roxmltree::Document::parse(xml.as_str())?; + let parser = format_if_error!(roxmltree::Document::parse(xml.as_str()), "Parsing XML file failed with: {error_text}")?; let children = parser.root().children(); for node in children { @@ -94,7 +94,7 @@ fn parse_boolean_attribute(xml: &roxmltree::Node, attribute_name: &str) -> Resul "true" | "1" => Ok(true), "false" | "0" => Ok(false), _ => { - return Err(Error::Generic(super::Error::from_text(format!("Attribute \"{}\" expects either true,false or 1,0 as valid attributes - found {}", attribute_name, bool_str)))); + return Err(Error::from_text(format!("Attribute \"{}\" expects either true,false or 1,0 as valid attributes - found {}", attribute_name, bool_str))); } } } @@ -102,30 +102,4 @@ fn parse_boolean_attribute(xml: &roxmltree::Node, attribute_name: &str) -> Resul else { Ok(false) } -} - -pub enum Error { - XML(roxmltree::Error), - Generic(super::Error) -} - -impl ErrorString for Error { - fn to_string(self) -> String { - match self { - Self::XML(xml) => xml.to_string(), - Self::Generic(generic) => generic.to_string() - } - } -} - -impl std::convert::From for Error { - fn from(error: roxmltree::Error) -> Error { - Error::XML(error) - } -} - -impl std::convert::From for Error { - fn from(error: super::Error) -> Error { - Error::Generic(error) - } } \ No newline at end of file