1#[derive(Debug)]
3pub struct Error {
4 pub msg: String,
5 pub err_type: ErrorType,
6}
7
8#[derive(Debug)]
10pub enum ErrorType {
11 Decode,
12 Generic,
13 Read,
14}
15
16impl std::fmt::Display for Error {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 write!(f, "vsd-mp4-error: {}", self.msg)
19 }
20}
21
22impl std::error::Error for Error {}
23
24impl Error {
25 pub fn new<T: Into<String>>(msg: T) -> Self {
27 Self {
28 err_type: ErrorType::Generic,
29 msg: msg.into(),
30 }
31 }
32
33 pub fn new_decode<T: Into<String>>(msg: T) -> Self {
35 Self {
36 err_type: ErrorType::Decode,
37 msg: format!("cannot decode {}", msg.into()),
38 }
39 }
40
41 pub fn new_read<T: Into<String>>(msg: T) -> Self {
43 Self {
44 err_type: ErrorType::Read,
45 msg: format!("cannot read {}", msg.into()),
46 }
47 }
48}