1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum EbookError {
6 Io(String),
8 Xml(String),
10 Zip(String),
12 DrmProtected(String),
14 InvalidFormat(String),
16 CorruptedData(String),
18 NotFound(String),
20 Custom(String),
22}
23
24impl fmt::Display for EbookError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 EbookError::Io(msg) => write!(f, "I/O Error: {}", msg),
28 EbookError::Xml(msg) => write!(f, "XML Parse Error: {}", msg),
29 EbookError::Zip(msg) => write!(f, "Zip Archive Error: {}", msg),
30 EbookError::DrmProtected(msg) => write!(f, "DRM Protected: {}", msg),
31 EbookError::InvalidFormat(msg) => write!(f, "Invalid Format: {}", msg),
32 EbookError::CorruptedData(msg) => write!(f, "Corrupted Data: {}", msg),
33 EbookError::NotFound(msg) => write!(f, "Not Found: {}", msg),
34 EbookError::Custom(msg) => write!(f, "{}", msg),
35 }
36 }
37}
38
39impl std::error::Error for EbookError {}
40
41impl From<std::io::Error> for EbookError {
42 fn from(err: std::io::Error) -> Self {
43 EbookError::Io(err.to_string())
44 }
45}
46
47impl From<String> for EbookError {
48 fn from(msg: String) -> Self {
49 EbookError::Custom(msg)
50 }
51}
52
53impl From<&str> for EbookError {
54 fn from(msg: &str) -> Self {
55 EbookError::Custom(msg.to_string())
56 }
57}
58
59impl From<EbookError> for String {
60 fn from(err: EbookError) -> Self {
61 err.to_string()
62 }
63}