use std::{
error::Error,
fmt::{self, Debug, Display, Formatter},
io,
};
#[derive(Debug)]
pub enum LyricsError {
ParseError(String),
IDTagError(IDTagErrorKind),
FormatError(&'static str),
IoError(io::Error),
}
impl PartialEq for LyricsError {
#[inline]
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(LyricsError::ParseError(a), LyricsError::ParseError(b)) => a == b,
(LyricsError::IDTagError(a), LyricsError::IDTagError(b)) => a == b,
(LyricsError::FormatError(a), LyricsError::FormatError(b)) => a == b,
_ => false,
}
}
}
impl Display for LyricsError {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match self {
LyricsError::ParseError(s) => f.write_str(s),
LyricsError::IDTagError(k) => f.write_fmt(format_args!("Set a wrong {}.", k)),
LyricsError::FormatError(s) => f.write_str(s),
LyricsError::IoError(e) => Display::fmt(e, f),
}
}
}
impl Error for LyricsError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
LyricsError::IoError(e) => Some(e),
_ => None,
}
}
}
impl From<io::Error> for LyricsError {
#[inline]
fn from(e: io::Error) -> LyricsError {
LyricsError::IoError(e)
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum IDTagErrorKind {
Label,
Text,
}
impl Display for IDTagErrorKind {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match self {
IDTagErrorKind::Label => f.write_str("label"),
IDTagErrorKind::Text => f.write_str("text"),
}
}
}
impl Error for IDTagErrorKind {}