use crate::CpuError; use core::fmt; #[derive(Debug)] #[non_exhaustive] pub enum RuntimeError { RomParse(String), MapperInit(String), Cpu(CpuError), BufferTooSmall { expected: usize, got: usize }, InvalidState(String), } impl fmt::Display for RuntimeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::RomParse(e) => write!(f, "ROM parse error: {e}"), Self::MapperInit(e) => write!(f, "mapper init error: {e}"), Self::Cpu(e) => write!(f, "CPU error: {e:?}"), Self::BufferTooSmall { expected, got } => { write!(f, "buffer too small: expected {expected} bytes, got {got}") } Self::InvalidState(e) => write!(f, "invalid runtime state: {e}"), } } } impl std::error::Error for RuntimeError {}