#[macro_export]
macro_rules! lazy_env_parse {
($key:expr_2021, Option<String>) => {
std::sync::LazyLock::new(|| std::env::var($key).ok())
};
($key:expr_2021, $t:ty) => {
std::sync::LazyLock::new(|| {
std::env::var($key).ok().and_then(|s| s.parse::<$t>().ok()).unwrap_or_default()
})
};
($key:expr_2021, $t:ty, || $default:expr_2021) => {
std::sync::LazyLock::new(|| {
std::env::var($key).ok().and_then(|s| s.parse::<$t>().ok()).unwrap_or_else(|| $default)
})
};
($key:expr_2021, $t:ty, $default:expr_2021) => {
std::sync::LazyLock::new(|| {
std::env::var($key).ok().and_then(|s| s.parse::<$t>().ok()).unwrap_or($default)
})
};
(bytes, $key:expr_2021, $t:ty, || $default:expr_2021) => {
std::sync::LazyLock::new(|| {
std::env::var($key)
.ok()
.and_then(|s| {
use $crate::str::ParseBytes;
s.parse_bytes::<$t>().ok()
})
.unwrap_or_else(|| $default)
})
};
(bytes, $key:expr_2021, $t:ty, $default:expr_2021) => {
std::sync::LazyLock::new(|| {
std::env::var($key)
.ok()
.and_then(|s| {
use $crate::str::ParseBytes;
s.parse_bytes::<$t>().ok()
})
.unwrap_or($default)
})
};
}
#[macro_export]
macro_rules! fail {
($($arg:tt)+) => {
return ::core::result::Result::Err(
::core::convert::Into::into(
$crate::EngineError::unreachable(::core::format_args!($($arg)*))
)
)
};
}