diff --git a/src/main.rs b/src/main.rs index 9742412..7192c2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,13 +49,15 @@ fn main() { let contents = fs::read_to_string(inputfile).expect("Should have been able to read the file"); - if let Ok(data) = from_str::(contents.as_str()) { - data.list_forms() - } else { - eprintln!("Kann Eingabedatei nicht lesen!"); - eprintln!( - "Die Datei ist entweder keine OSC-Datei, fehlerhaft oder enthält zusätzliche Inhalte." - ); + match OnkostarEditor::from_str(contents.as_str()) { + Ok(data) => data.list_forms(), + Err(err) => { + eprintln!("Kann Eingabedatei nicht lesen!"); + eprintln!( + "Die Datei ist entweder keine OSC-Datei, fehlerhaft oder enthält zusätzliche Inhalte:\n{}", + err + ); + } } } Command::Modify { diff --git a/src/model/onkostar_editor.rs b/src/model/onkostar_editor.rs index 7087aaf..d40f3e2 100644 --- a/src/model/onkostar_editor.rs +++ b/src/model/onkostar_editor.rs @@ -23,7 +23,9 @@ */ use console::style; +use quick_xml::de::from_str; use serde::{Deserialize, Serialize}; +use std::str::FromStr; use crate::model::data_catalogue::DataCatalogue; use crate::model::data_form::DataForm; @@ -96,6 +98,17 @@ impl OnkostarEditor { } } +impl FromStr for OnkostarEditor { + type Err = String; + + fn from_str(s: &str) -> Result { + match from_str::(s) { + Ok(profile) => Ok(profile), + Err(err) => Err(err.to_string()), + } + } +} + #[derive(Serialize, Deserialize, Debug)] #[serde(deny_unknown_fields)] pub struct InfoXML {