types (macros): use `.ok_or(...)` in `option_return` macro
This commit is contained in:
parent
e3a8bf3550
commit
99f0623f1f
|
@ -10,7 +10,7 @@ impl Config {
|
||||||
/// parse configuration file
|
/// parse configuration file
|
||||||
pub fn parse() -> Result<Config> {
|
pub fn parse() -> Result<Config> {
|
||||||
// configuration file path
|
// configuration file path
|
||||||
let config_dir = option_return!(dirs::config_dir(), "s")?;
|
let config_dir = option_return!(dirs::config_dir(), "get config dir")?;
|
||||||
|
|
||||||
let config_path = format!("{}/homedisk/config.toml", config_dir.to_string_lossy());
|
let config_path = format!("{}/homedisk/config.toml", config_dir.to_string_lossy());
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! option_return {
|
macro_rules! option_return {
|
||||||
($a:expr,$b:expr) => {
|
($variable:expr,$err_desc:expr) => {
|
||||||
match $a {
|
$variable.ok_or(std::io::Error::new(std::io::ErrorKind::Other, $err_desc))
|
||||||
Some(x) => Ok(x),
|
|
||||||
None => {
|
|
||||||
let err = std::io::Error::new(std::io::ErrorKind::Other, $b);
|
|
||||||
Err(anyhow::Error::from(err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue