rust-uio
rust-uio copied to clipboard
Adding Error trait to UioError
Hey, thanks for this crate :)
Would it be possible to add the Error trait to UioError, so that it can play nicely with Anyhow (and I suppose other error handling crates) ?
I've never done it before, but I looked how Deku was doing it ( https://docs.rs/deku/0.17.0/src/deku/error.rs.html#74 ) and adding this should work :
impl Error for UioError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(self)
}
}
impl Display for UioError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
UioError::Address => write!(f, "Invalid address "),
UioError::Size => write!(f, "Invalid Size "),
UioError::Io(ref err) => write!(f, "IO error: {err} "),
UioError::Map(ref err) => write!(f, "Map error: {err} "),
UioError::Parse => write!(f, "Parse error"),
}
}
}