1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
6
7#[derive(Debug, Error)]
8pub enum Error {
9 #[error("I/O error: {0}")]
10 Io(#[from] std::io::Error),
11
12 #[error("unsupported: {0}")]
13 Unsupported(String),
14
15 #[error("invalid data: {0}")]
16 InvalidData(String),
17
18 #[error("end of stream")]
19 Eof,
20
21 #[error("need more data")]
22 NeedMore,
23
24 #[error("format not found: {0}")]
25 FormatNotFound(String),
26
27 #[error("codec not found: {0}")]
28 CodecNotFound(String),
29
30 #[error("{0}")]
31 Other(String),
32}
33
34impl Error {
35 pub fn unsupported(msg: impl Into<String>) -> Self {
36 Self::Unsupported(msg.into())
37 }
38
39 pub fn invalid(msg: impl Into<String>) -> Self {
40 Self::InvalidData(msg.into())
41 }
42
43 pub fn other(msg: impl Into<String>) -> Self {
44 Self::Other(msg.into())
45 }
46}