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}
17
18pub type Result<T> = std::result::Result<T, Error>;
20
21impl fmt::Display for Error {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Error::Io(e) => write!(f, "I/O error: {e}"),
25 Error::Decode(e) => write!(f, "could not decode sound: {e}"),
26 Error::Audio(e) => write!(f, "audio device error: {e}"),
27 Error::Window(e) => write!(f, "window error: {e}"),
28 }
29 }
30}
31
32impl std::error::Error for Error {
33 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
34 match self {
35 Error::Io(e) => Some(e),
36 _ => None,
37 }
38 }
39}
40
41impl From<std::io::Error> for Error {
42 fn from(e: std::io::Error) -> Self {
43 Error::Io(e)
44 }
45}