From ad193377608347e010593d12c65f89acefc262c7 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sun, 11 Oct 2020 09:04:53 +0800 Subject: [PATCH] generate: impl Error for ParseError Signed-off-by: Sean Cross --- svd2utra/src/generate.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/svd2utra/src/generate.rs b/svd2utra/src/generate.rs index 585a718dc..db0082b60 100644 --- a/svd2utra/src/generate.rs +++ b/svd2utra/src/generate.rs @@ -54,6 +54,21 @@ pub struct Description { pub memory_regions: Vec, } +impl core::fmt::Display for ParseError { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + use ParseError::*; + match *self { + UnexpectedTag => write!(f, "unexpected XML tag encountered"), + MissingValue => write!(f, "XML tag should have contained a value"), + ParseIntError => write!(f, "unable to parse number"), + NonUTF8 => write!(f, "file is not UTF-8"), + WriteError => write!(f, "unable to write destination file"), + } + } +} + +impl std::error::Error for ParseError {} + pub fn get_base(value: &str) -> (&str, u32) { if value.starts_with("0x") { (value.trim_start_matches("0x"), 16)