1use std::io;
2use thiserror::Error;
3
4pub type Result<T> = std::result::Result<T, RpgError>;
6
7#[derive(Debug, Error)]
9pub enum RpgError {
10 #[error("IO error: {0}")]
12 Io(#[from] io::Error),
13 #[error("Encode error: {message} (format: {format})")]
15 Encode {
16 message: String,
18 format: &'static str,
20 },
21 #[error("Decode error: {message} (format: {format})")]
23 Decode {
24 message: String,
26 format: &'static str,
28 },
29}
30
31impl RpgError {
32 pub fn decode(format: &'static str, message: &str) -> Self {
34 Self::Decode { message: message.to_string(), format }
35 }
36
37 pub fn encode(format: &'static str, message: &str) -> Self {
39 Self::Encode { message: message.to_string(), format }
40 }
41}