Debian Codegraph @

third_party/rust/embed-manifest/src/embed/error.rs

raw
1 //! Error handling for application manifest embedding.
2
3 use std::fmt::{self, Display, Formatter};
4 use std::io::{self, ErrorKind};
5
6 /// The error type which is returned when application manifest embedding fails.
7 #[derive(Debug)]
8 pub struct Error {
9 repr: Repr,
10 }
11
12 #[derive(Debug)]
13 enum Repr {
14 IoError(io::Error),
15 UnknownTarget,
16 }
17
18 impl Error {
19 pub(crate) fn unknown_target() -> Error {
20 Error {
21 repr: Repr::UnknownTarget,
22 }
23 }
24 }
25
26 impl Display for Error {
27 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
28 match self.repr {
29 Repr::IoError(ref e) => write!(f, "I/O error: {}", e),
30 Repr::UnknownTarget => f.write_str("unknown target"),
31 }
32 }
33 }
34
35 impl std::error::Error for Error {
36 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
37 match self.repr {
38 Repr::IoError(ref e) => Some(e),
39 _ => None,
40 }
41 }
42 }
43
44 impl From<io::Error> for Error {
45 fn from(e: io::Error) -> Self {
46 Error { repr: Repr::IoError(e) }
47 }
48 }
49
50 impl From<Error> for io::Error {
51 fn from(e: Error) -> Self {
52 match e.repr {
53 Repr::IoError(ioe) => ioe,
54 _ => io::Error::new(ErrorKind::Other, e),
55 }
56 }
57 }