use std::fmt::{self, Display, Formatter};
#[derive(Debug)]
pub enum Error {
InvalidData(String),
Io(std::io::Error),
Chart(charts_rs::Error),
Audio(String),
Gui(String),
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidData(msg) => write!(f, "invalid input data: {msg}"),
Self::Io(e) => write!(f, "I/O error: {e}"),
Self::Chart(e) => write!(f, "chart rendering error: {e}"),
Self::Audio(msg) => write!(f, "audio backend error: {msg}"),
Self::Gui(msg) => write!(f, "GUI error: {msg}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::InvalidData(_) | Self::Audio(_) | Self::Gui(_) => None,
Self::Io(e) => Some(e),
Self::Chart(e) => Some(e),
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Io(e)
}
}
impl From<charts_rs::Error> for Error {
fn from(e: charts_rs::Error) -> Self {
Self::Chart(e)
}
}