generate: impl Error for ParseError

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-10-11 09:04:53 +08:00
parent 3590fa3d4b
commit ad19337760

View file

@ -54,6 +54,21 @@ pub struct Description {
pub memory_regions: Vec<MemoryRegion>,
}
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)