1use std::error::Error;
2use std::fmt::Display;
3#[derive(Debug)]
4pub enum RetroRsError {
5 NoFramebufferError,
6 ImageBufferError,
7 TryFromIntError(std::num::TryFromIntError),
8 RAMCopyDestTooSmallError,
9 RAMCopySrcOutOfBoundsError,
10 RAMMapOutOfRangeError,
11 RAMCopyCrossedRegionError,
12 RAMCopyNotMappedIntoMemoryRegionError,
13}
14impl From<std::num::TryFromIntError> for RetroRsError {
15 fn from(err: std::num::TryFromIntError) -> RetroRsError {
16 RetroRsError::TryFromIntError(err)
17 }
18}
19impl Display for RetroRsError {
20 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21 match *self {
22 RetroRsError::NoFramebufferError => {
23 write!(f, "This emulator does not have a framebuffer yet.")
24 }
25 RetroRsError::ImageBufferError => write!(f, "Failure in creating image buffer"),
26 RetroRsError::TryFromIntError(ref err) => err.fmt(f),
27 RetroRsError::RAMCopyDestTooSmallError => {
28 write!(f, "Destination for RAM copy too small")
29 }
30 RetroRsError::RAMCopySrcOutOfBoundsError => {
31 write!(f, "Source address range for RAM copy out of bounds")
32 }
33 RetroRsError::RAMMapOutOfRangeError => {
34 write!(f, "Given memory map is not valid for this core")
35 }
36 RetroRsError::RAMCopyCrossedRegionError => {
37 write!(f, "RAM copy crossed over memory region boundaries")
38 }
39 RetroRsError::RAMCopyNotMappedIntoMemoryRegionError => {
40 write!(f, "RAM copy doesn't start within a memory region")
41 }
42 }
43 }
44}
45impl Error for RetroRsError {}