Files
porcel8/src/util.rs

52 lines
1.4 KiB
Rust
Raw Normal View History

2024-03-05 18:37:57 +05:30
use std::sync::mpsc::SendError;
use std::sync::PoisonError;
use sdl2::IntegerOrSdlError;
use sdl2::video::WindowBuildError;
2024-03-05 18:37:57 +05:30
use crate::device::keyboard::KeyboardEvent;
pub type EmulatorResult<T> = Result<T, EmulatorError>;
2024-03-05 09:33:53 +05:30
#[derive(Clone, Debug)]
pub enum EmulatorError {
SdlError(String),
IOError(String),
MutexInvalidState(String)
}
impl From<String> for EmulatorError {
fn from(value: String) -> Self {
Self::SdlError(value)
}
}
impl From<WindowBuildError> for EmulatorError {
fn from(value: WindowBuildError) -> Self {
Self::SdlError(value.to_string())
}
}
impl From<IntegerOrSdlError> for EmulatorError {
fn from(value: IntegerOrSdlError) -> Self {
match value {
IntegerOrSdlError::IntegerOverflows(x, y) => { Self::SdlError(format!("{} - {}", x, y)) }
IntegerOrSdlError::SdlError(str) => { Self::SdlError(str) }
}
}
}
impl From<std::io::Error> for EmulatorError{
fn from(value: std::io::Error) -> Self {
Self::IOError(value.to_string())
}
}
impl<T> From<PoisonError<T>> for EmulatorError{
fn from(value: PoisonError<T>) -> Self {
Self::MutexInvalidState(value.to_string())
}
2024-03-05 09:33:53 +05:30
}
2024-03-05 18:37:57 +05:30
impl From<SendError<KeyboardEvent>> for EmulatorError{
fn from(value: SendError<KeyboardEvent>) -> Self {
2024-03-06 08:18:07 +05:30
Self::IOError(format!("Failed to communicate keyboard event to main thread: {}",value))
2024-03-05 18:37:57 +05:30
}
}