1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::error::Error;
use std::fmt::{self, Debug, Display, Formatter};

#[derive(Debug, PartialEq)]
pub enum LyricsError {
    ParseError(String),
    IDTagError(IDTagErrorKind),
    FormatError(&'static str),
}

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),
        }
    }
}

impl Error for LyricsError {}

#[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 {}