Rewrote project in Rust

This commit is contained in:
a2x
2023-09-26 00:46:10 +10:00
parent a8d3318d94
commit 369ebcf238
136 changed files with 47374 additions and 47187 deletions

48
src/error.rs Normal file
View File

@@ -0,0 +1,48 @@
use std::io;
#[derive(Debug)]
pub enum Error {
InvalidMagic(u32),
IOError(io::Error),
ModuleNotFound,
PatternNotFound,
ProcessNotFound,
SerdeError(serde_json::Error),
Utf8Error(std::string::FromUtf8Error),
WindowsError(windows::core::Error),
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::IOError(err)
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(err: std::string::FromUtf8Error) -> Self {
Self::Utf8Error(err)
}
}
impl From<windows::core::Error> for Error {
fn from(err: windows::core::Error) -> Self {
Self::WindowsError(err)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::InvalidMagic(magic) => write!(fmt, "Invalid magic: {:#X}", magic),
Self::IOError(err) => write!(fmt, "IO error: {}", err),
Self::ModuleNotFound => write!(fmt, "Module not found"),
Self::PatternNotFound => write!(fmt, "Pattern not found"),
Self::ProcessNotFound => write!(fmt, "Process not found"),
Self::SerdeError(err) => write!(fmt, "Serde error: {}", err),
Self::Utf8Error(err) => write!(fmt, "UTF-8 error: {}", err),
Self::WindowsError(err) => write!(fmt, "Windows error: {}", err),
}
}
}
pub type Result<T> = std::result::Result<T, Error>;