openh264_sys2/
error.rs

1use std::fmt::{Display, Formatter};
2
3#[derive(Debug)]
4pub enum Error {
5    /// Indicates we could not open a file as a shared library.
6    #[cfg(feature = "libloading")]
7    LibLoading(libloading::Error),
8
9    /// Could not read data.
10    Io(std::io::Error),
11
12    /// The given hash was not amongst the known hashes we should load.
13    InvalidHash(String),
14}
15
16#[cfg(feature = "libloading")]
17impl From<libloading::Error> for Error {
18    fn from(value: libloading::Error) -> Self {
19        Self::LibLoading(value)
20    }
21}
22
23impl From<std::io::Error> for Error {
24    fn from(value: std::io::Error) -> Self {
25        Self::Io(value)
26    }
27}
28
29impl Display for Error {
30    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31        #[allow(unreachable_patterns)]
32        match self {
33            #[cfg(feature = "libloading")]
34            Error::LibLoading(x) => x.fmt(f),
35            Error::Io(x) => x.fmt(f),
36            Error::InvalidHash(x) => format!("Invalid hash: {x}").fmt(f),
37            _ => "".fmt(f),
38        }
39    }
40}
41
42impl std::error::Error for Error {}