1use std::fmt;
2use std::io;
3
4use crate::config;
5use crate::thread_pool;
6
7#[derive(Debug)]
8pub enum Error {
9 Io(io::Error),
10 Config(config::Error),
11 ThreadPool(thread_pool::Error),
12}
13
14impl fmt::Display for Error {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 match self {
17 Error::Io(e) => write!(f, "I/O Error: {e}"),
18 Error::Config(e) => write!(f, "Configuration error: {e}"),
19 Error::ThreadPool(e) => write!(f, "Thread pool error: {e}"),
20 }
21 }
22}
23
24impl From<config::Error> for Error {
25 fn from(error: config::Error) -> Self {
26 Error::Config(error)
27 }
28}
29
30impl From<io::Error> for Error {
31 fn from(error: io::Error) -> Self {
32 Error::Io(error)
33 }
34}
35
36impl From<thread_pool::Error> for Error {
37 fn from(error: thread_pool::Error) -> Self {
38 Error::ThreadPool(error)
39 }
40}
41
42impl std::error::Error for Error {
43 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
44 match self {
45 Error::Io(e) => Some(e),
46 Error::Config(e) => Some(e),
47 Error::ThreadPool(e) => Some(e),
48 }
49 }
50}