1#[derive(Debug)]
2pub(crate) enum Error {
3 Cargo(std::io::Error),
4 CargoExpandExecution(String),
5 CargoFail,
6 CargoMetadata(serde_json::error::Error),
7 Io(std::io::Error),
8 TomlSer(toml::ser::Error),
9 TomlDe(toml::de::Error),
10 Glob(glob::GlobError),
11 GlobPattern(glob::PatternError),
12 ManifestDir,
13 PkgName,
14 UnrecognizedEnv(std::ffi::OsString),
15}
16
17pub(crate) type Result<T> = std::result::Result<T, Error>;
18
19impl std::fmt::Display for Error {
20 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21 use self::Error::*;
22
23 match self {
24 Cargo(e) => write!(f, "{}", e),
25 CargoExpandExecution(e) => write!(f, "Failed to execute cargo command: {}", e),
26 CargoFail => write!(f, "cargo reported an error"),
27 CargoMetadata(e) => write!(f, "{}", e),
28 Io(e) => write!(f, "{}", e),
29 TomlSer(e) => write!(f, "{}", e),
30 TomlDe(e) => write!(f, "{}", e),
31 Glob(e) => write!(f, "{}", e),
32 GlobPattern(e) => write!(f, "{}", e),
33 ManifestDir => write!(f, "could not find CARGO_MANIFEST_DIR env var"),
34 PkgName => write!(f, "could not find CARGO_PKG_NAME env var"),
35 UnrecognizedEnv(e) => write!(
36 f,
37 "unrecognized value of MACROTEST: \"{}\"",
38 e.to_string_lossy()
39 ),
40 }
41 }
42}
43
44impl From<std::io::Error> for Error {
45 fn from(e: std::io::Error) -> Self {
46 Error::Io(e)
47 }
48}
49
50impl From<toml::ser::Error> for Error {
51 fn from(e: toml::ser::Error) -> Self {
52 Error::TomlSer(e)
53 }
54}
55
56impl From<toml::de::Error> for Error {
57 fn from(e: toml::de::Error) -> Self {
58 Error::TomlDe(e)
59 }
60}
61
62impl From<glob::GlobError> for Error {
63 fn from(e: glob::GlobError) -> Self {
64 Error::Glob(e)
65 }
66}
67
68impl From<glob::PatternError> for Error {
69 fn from(e: glob::PatternError) -> Self {
70 Error::GlobPattern(e)
71 }
72}