Skip to content
Snippets Groups Projects
Verified Commit 23b76861 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: made Error implement the Error trait

parent 3ebe1bcb
No related branches found
No related tags found
No related merge requests found
Pipeline #4885 failed
......@@ -6,9 +6,7 @@
//! errors that can occur within Boytacean domain.
use std::{
fmt::{self, Display, Formatter},
io,
string::FromUtf8Error,
error, fmt::{self, Display, Formatter}, io, string::FromUtf8Error
};
/// Top level enum for error handling within Boytacean.
......@@ -42,6 +40,30 @@ impl Error {
}
}
impl error::Error for Error {
fn description(&self) -> &str {
match self {
Error::InvalidData => "Invalid data format",
Error::InvalidKey => "Invalid key",
Error::RomSize => "Invalid ROM size",
Error::IncompatibleBootRom => "Incompatible Boot ROM",
Error::MissingOption(_) => "Missing option",
Error::IoError(_) => "IO error",
Error::InvalidParameter(_) => "Invalid parameter",
Error::CustomError(_) => "Custom error",
}
}
fn cause(&self) -> Option<&dyn error::Error> {
None
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
None
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.description())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment