embed_manifest/embed/
error.rs1use std::fmt::{self, Display, Formatter};
4use std::io;
5
6#[derive(Debug)]
8pub struct Error {
9 repr: Repr,
10}
11
12#[derive(Debug)]
13enum Repr {
14 IoError(io::Error),
15 UnknownTarget,
16}
17
18impl Error {
19 pub(crate) fn unknown_target() -> Error {
20 Error {
21 repr: Repr::UnknownTarget,
22 }
23 }
24}
25
26impl 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
35impl 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
44impl From<io::Error> for Error {
45 fn from(e: io::Error) -> Self {
46 Error { repr: Repr::IoError(e) }
47 }
48}
49
50impl From<Error> for io::Error {
51 fn from(e: Error) -> Self {
52 match e.repr {
53 Repr::IoError(ioe) => ioe,
54 _ => io::Error::other(e),
55 }
56 }
57}