1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
mod backend;
mod builder;
mod config;
pub mod documentation;
pub use backend::{Backend, Callbacks, Resolver};
pub use builder::{Builder, Package};
pub use config::ConfigFile;
pub use simplelog::LevelFilter;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("{0}")]
Toml(#[from] toml::de::Error),
#[error("Error at {0}: {1}")]
Io(std::path::PathBuf, std::io::Error),
#[error("{0}")]
Syn(#[from] syn::Error),
#[error("{0}")]
Metadata(#[from] cargo_metadata::Error),
#[error("No crate matched the name '{0}'")]
NoMatchingCrate(String),
#[error(
r"Multiple crates were found with a 'cdylib' target: {0:?}
Please select the one you want via either:
- The '-p' flag on the command line
- The `package` method of `Builder`
"
)]
MultipleCandidateCrate(Vec<String>),
#[error("No crate was found with a 'cdylib' target")]
NoCandidateCrate,
#[error("Logger initialization failed: {0}")]
InitLogger(#[from] log::SetLoggerError),
}
pub type Result<T> = std::result::Result<T, Error>;
pub fn init_logger(level: LevelFilter) -> Result<()> {
simplelog::TermLogger::init(
level,
simplelog::Config::default(),
simplelog::TerminalMode::Stderr,
)?;
Ok(())
}