rosu_memory_lib/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5    /// Error when reading memory
6    MemoryRead(String),
7    /// Error when parsing data
8    Parse(String),
9    /// Error when a feature is not available
10    NotAvailable(String),
11    /// Error when a file operation fails
12    FileOperation(String),
13    /// Error when an operation is not supported
14    Unsupported(String),
15    /// Other general errors
16    Other(String),
17}
18
19impl std::error::Error for Error {}
20
21impl fmt::Display for Error {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        match self {
24            Error::MemoryRead(msg) => write!(f, "Memory read error: {msg}"),
25            Error::Parse(msg) => write!(f, "Parse error: {msg}"),
26            Error::NotAvailable(msg) => write!(f, "Not available: {msg}"),
27            Error::FileOperation(msg) => write!(f, "File operation error: {msg}"),
28            Error::Unsupported(msg) => write!(f, "Unsupported operation: {msg}"),
29            Error::Other(msg) => write!(f, "Error: {msg}"),
30        }
31    }
32}
33
34impl From<std::io::Error> for Error {
35    fn from(err: std::io::Error) -> Self {
36        Error::FileOperation(err.to_string())
37    }
38}
39
40impl From<rosu_mem::error::ProcessError> for Error {
41    fn from(err: rosu_mem::error::ProcessError) -> Self {
42        Error::MemoryRead(err.to_string())
43    }
44}
45
46impl From<rosu_mem::error::ParseSignatureError> for Error {
47    fn from(err: rosu_mem::error::ParseSignatureError) -> Self {
48        Error::Parse(err.to_string())
49    }
50}
51
52pub type Result<T> = std::result::Result<T, Error>;