rea_rs/
errors.rs

1use std::{error::Error, fmt::Display};
2
3use serde_derive::{Deserialize, Serialize};
4
5#[derive(Debug, PartialEq, Serialize, Deserialize)]
6pub enum ReaperError {
7    UserAborted,
8    Unexpected,
9    InvalidObject(&'static str),
10    UnsuccessfulOperation(&'static str),
11    NullPtr,
12    Str(&'static str),
13}
14impl Error for ReaperError {}
15impl Display for ReaperError {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        match self {
18            Self::Unexpected => write!(f, "Unexpected error happened."),
19            Self::UserAborted => write!(f, "User aborted operation."),
20            Self::InvalidObject(s) => write!(f, "Invalid object: {}", *s),
21            Self::UnsuccessfulOperation(s) => {
22                write!(f, "Unsuccessful operation: {}", *s)
23            }
24            Self::NullPtr => write!(f, "NullPtr!"),
25            Self::Str(s) => write!(f, "{}", *s),
26        }
27    }
28}
29
30pub type ReaperResult<T> = Result<T, Box<dyn Error>>;
31pub type ReaperStaticResult<T> = Result<T, ReaperError>;