[err] Error names

This commit is contained in:
2024-02-17 11:22:26 +05:30
parent 1aecdacfde
commit 562a33cdc2
4 changed files with 9 additions and 9 deletions

View File

@@ -15,7 +15,7 @@ impl RamMemory {
pub fn try_new() -> EmulatorResult<RamMemory> { pub fn try_new() -> EmulatorResult<RamMemory> {
let alloc_result = vec![0; MEM_LENGTH].into_boxed_slice(); let alloc_result = vec![0; MEM_LENGTH].into_boxed_slice();
let data = alloc_result.try_into().map_err(|err|{ let data = alloc_result.try_into().map_err(|err|{
EmulatorError::AllocationError(RAM,"Allocation failed") EmulatorError::AllocationFailure(RAM, "Allocation failed")
})?; })?;
Ok(RamMemory { Ok(RamMemory {
data data
@@ -27,13 +27,13 @@ impl RamMemory {
impl Memory for RamMemory { impl Memory for RamMemory {
fn try_get_byte(&self, address: u32) -> EmulatorResult<u8> { fn try_get_byte(&self, address: u32) -> EmulatorResult<u8> {
log::trace!("Fetch RAM memory at address {}",address); log::trace!("Fetch RAM memory at address {}",address);
let x = *self.data.get(address as usize).ok_or(EmulatorError::UnreachableMemoryError(RAM,address))?; let x = *self.data.get(address as usize).ok_or(EmulatorError::UnreachableMemory(RAM, address))?;
Ok(x) Ok(x)
} }
fn try_set_byte(&mut self, address: u32, value: u8) -> EmulatorResult<()> { fn try_set_byte(&mut self, address: u32, value: u8) -> EmulatorResult<()> {
if address>= MEM_LENGTH as u32 { if address>= MEM_LENGTH as u32 {
return Err(EmulatorError::UnreachableMemoryError(RAM,address)) return Err(EmulatorError::UnreachableMemory(RAM, address))
} }
self.data[address as usize] = value; self.data[address as usize] = value;
Ok(()) Ok(())

View File

@@ -2,7 +2,7 @@ use crate::emu::iomem::MemoryMappedIO;
use crate::emu::mem::RamMemory; use crate::emu::mem::RamMemory;
use crate::misc::emulator_error::DeviceType::MMU; use crate::misc::emulator_error::DeviceType::MMU;
use crate::misc::emulator_error::EmulatorError::UnreachableMemoryError; use crate::misc::emulator_error::EmulatorError::UnreachableMemory;
use crate::misc::result::EmulatorResult; use crate::misc::result::EmulatorResult;
// 8 bytes that are memory mapped i/o // 8 bytes that are memory mapped i/o
@@ -44,7 +44,7 @@ impl Memory for MappedMemory {
RAM_MEM_START..=RAM_MEM_END => { RAM_MEM_START..=RAM_MEM_END => {
self.ram_memory.try_get_byte(address) self.ram_memory.try_get_byte(address)
} }
_ => { Err(UnreachableMemoryError(MMU, address)) } _ => { Err(UnreachableMemory(MMU, address)) }
}?; }?;
Ok(byte_at_addr) Ok(byte_at_addr)

View File

@@ -19,7 +19,7 @@ impl Color {
} }
pub fn try_new(in_mem_color: u8) -> EmulatorResult<Color> { pub fn try_new(in_mem_color: u8) -> EmulatorResult<Color> {
if in_mem_color > Self::COLOR_MAX { if in_mem_color > Self::COLOR_MAX {
return Err(EmulatorError::InvalidColorError(in_mem_color)) return Err(EmulatorError::InvalidColor(in_mem_color))
} }
Ok(Color(in_mem_color)) Ok(Color(in_mem_color))
} }

View File

@@ -11,9 +11,9 @@ pub enum DeviceType {
#[derive(Debug)] #[derive(Debug)]
pub enum EmulatorError { pub enum EmulatorError {
AllocationError(DeviceType, &'static str), AllocationFailure(DeviceType, &'static str),
UnreachableMemoryError(DeviceType, u32), UnreachableMemory(DeviceType, u32),
InvalidColorError(u8) InvalidColor(u8)
} }