types (macros): use `.ok_or(...)` in `option_return` macro

This commit is contained in:
MedzikUser 2022-04-19 21:18:45 +02:00
parent e3a8bf3550
commit 99f0623f1f
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
2 changed files with 3 additions and 9 deletions

View File

@ -10,7 +10,7 @@ impl Config {
/// parse configuration file
pub fn parse() -> Result<Config> {
// 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());

View File

@ -1,12 +1,6 @@
#[macro_export]
macro_rules! option_return {
($a:expr,$b:expr) => {
match $a {
Some(x) => Ok(x),
None => {
let err = std::io::Error::new(std::io::ErrorKind::Other, $b);
Err(anyhow::Error::from(err))
}
}
($variable:expr,$err_desc:expr) => {
$variable.ok_or(std::io::Error::new(std::io::ErrorKind::Other, $err_desc))
};
}