playlist_decoder/
decode_error.rs

1use std::error::Error;
2use std::fmt;
3
4use quick_xml::encoding::EncodingError;
5use quick_xml::events::attributes::AttrError;
6
7#[derive(Debug)]
8pub struct PlaylistDecodeError {
9    details: String,
10}
11
12impl PlaylistDecodeError {
13    pub fn new(msg: &str) -> PlaylistDecodeError {
14        PlaylistDecodeError {
15            details: msg.to_string(),
16        }
17    }
18}
19
20impl fmt::Display for PlaylistDecodeError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        write!(f, "DecodeError: {}", self.details)
23    }
24}
25
26impl Error for PlaylistDecodeError {}
27
28impl From<AttrError> for PlaylistDecodeError {
29    fn from(_value: AttrError) -> Self {
30        PlaylistDecodeError {
31            details: String::from("XML: AttrError"),
32        }
33    }
34}
35
36impl From<EncodingError> for PlaylistDecodeError {
37    fn from(_value: EncodingError) -> Self {
38        PlaylistDecodeError {
39            details: String::from("XML: EncodingError"),
40        }
41    }
42}
43
44impl From<quick_xml::Error> for PlaylistDecodeError {
45    fn from(_value: quick_xml::Error) -> Self {
46        PlaylistDecodeError {
47            details: String::from("XML: generic error"),
48        }
49    }
50}