alpha2_container/
error.rs1use alpha2_media::{DecodeError, EncodeError};
4
5#[derive(Debug)]
7pub enum DemuxError {
8 Unsupported(String),
10 Invalid(String),
12 NoSuchTrack(u32),
14 Io(std::io::Error),
16}
17
18impl std::fmt::Display for DemuxError {
19 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 match self {
21 Self::Unsupported(reason) => write!(formatter, "{reason}"),
22 Self::Invalid(reason) => write!(formatter, "invalid media: {reason}"),
23 Self::NoSuchTrack(track) => write!(formatter, "no track {track}"),
24 Self::Io(error) => write!(formatter, "cannot read the file: {error}"),
25 }
26 }
27}
28
29impl std::error::Error for DemuxError {
30 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
31 match self {
32 Self::Io(error) => Some(error),
33 _ => None,
34 }
35 }
36}
37
38impl From<std::io::Error> for DemuxError {
39 fn from(error: std::io::Error) -> Self {
40 Self::Io(error)
41 }
42}
43
44impl From<DemuxError> for DecodeError {
45 fn from(error: DemuxError) -> Self {
46 match error {
47 DemuxError::Unsupported(reason) => Self::Unsupported(reason),
48 error => Self::Adapter(error.to_string()),
49 }
50 }
51}
52
53#[derive(Debug)]
55pub enum MuxError {
56 Unsupported(String),
58 Invalid(String),
60 Io(std::io::Error),
62}
63
64impl std::fmt::Display for MuxError {
65 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66 match self {
67 Self::Unsupported(reason) | Self::Invalid(reason) => write!(formatter, "{reason}"),
68 Self::Io(error) => write!(formatter, "cannot write the file: {error}"),
69 }
70 }
71}
72
73impl std::error::Error for MuxError {
74 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
75 match self {
76 Self::Io(error) => Some(error),
77 _ => None,
78 }
79 }
80}
81
82impl From<std::io::Error> for MuxError {
83 fn from(error: std::io::Error) -> Self {
84 Self::Io(error)
85 }
86}
87
88impl From<MuxError> for EncodeError {
89 fn from(error: MuxError) -> Self {
90 match error {
91 MuxError::Io(error) => Self::Output(error.to_string()),
92 error => Self::Adapter(error.to_string()),
93 }
94 }
95}