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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::{fmt, io};
#[derive(Debug)]
pub enum Error {
Mp3Error(Mp3Error),
IoError(io::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Mp3Error(e) => write!(f, "MP3 Error: {}", e),
Error::IoError(e) => write!(f, "IO Error: {}", e),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Mp3Error(e) => Some(e),
Error::IoError(e) => Some(e),
}
}
}
#[derive(Debug)]
pub enum Mp3Error {
InvalidData(&'static str),
Unsupported(&'static str),
}
impl fmt::Display for Mp3Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Mp3Error::InvalidData(s) => write!(f, "Invalid data: {}", s),
Mp3Error::Unsupported(s) => write!(f, "Unsupported: {}", s),
}
}
}
impl std::error::Error for Mp3Error {}
impl From<Mp3Error> for Error {
fn from(error: Mp3Error) -> Self {
Error::Mp3Error(error)
}
}
impl From<io::Error> for Error {
fn from(error: io::Error) -> Self {
Error::IoError(error)
}
}