1use std::fmt;
4
5#[derive(Debug)]
7pub enum Error {
8 Io(std::io::Error),
10 Decode(String),
12 Audio(String),
14 Window(String),
16 Net(String),
18}
19
20pub type Result<T> = std::result::Result<T, Error>;
22
23impl fmt::Display for Error {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 Error::Io(e) => write!(f, "I/O error: {e}"),
27 Error::Decode(e) => write!(f, "could not decode sound: {e}"),
28 Error::Audio(e) => write!(f, "audio device error: {e}"),
29 Error::Window(e) => write!(f, "window error: {e}"),
30 Error::Net(e) => write!(f, "network error: {e}"),
31 }
32 }
33}
34
35impl std::error::Error for Error {
36 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
37 match self {
38 Error::Io(e) => Some(e),
39 _ => None,
40 }
41 }
42}
43
44impl From<std::io::Error> for Error {
45 fn from(e: std::io::Error) -> Self {
46 Error::Io(e)
47 }
48}