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