#[macro_use]
mod result;
mod defer;
mod iter;
mod option;
mod peekable;
mod string;
pub use defer::*;
pub use iter::*;
pub use option::*;
pub use peekable::*;
pub use result::*;
pub use string::*;
#[macro_export]
macro_rules! function {
() => {{
fn _f() {}
fn type_of<T>(_: T) -> &'static str
{
std::any::type_name::<T>()
}
let fqn = type_of(_f);
let fqn = &fqn[..fqn.len() - 4];
match fqn.rfind(':') {
Some(i) => &fqn[i + 1..],
None => &fqn,
}
}};
}
#[macro_export]
macro_rules! function_fqn {
() => {{
fn _f() {}
fn type_of<T>(_: T) -> &'static str
{
std::any::type_name::<T>()
}
let fqn = type_of(_f);
let fqn = &fqn[..fqn.len() - 4];
fqn
}};
}
#[macro_export]
macro_rules! cfgblock {
(#[$attr:meta] $item:item) => {
#[$attr] $item
};
(#[$attr:meta] $($tail:item)*) => {
$(cfgblock!{#[$attr] $tail})*
};
}
#[macro_export]
macro_rules! defer {
($($tokens:tt)*) => {
let _defer = defer(|| { $($tokens)* });
};
}
#[macro_export]
macro_rules! trying {
($e:expr) => {
match $e {
Ok(v) => v,
Err(err) => return Some(Err(From::from(err))),
}
};
}
#[cfg(test)]
mod tests
{
use crate::prelude::*;
#[test]
fn test_function_fqn_macro()
{
fn indirect_fqn() -> &'static str
{
function_fqn!()
}
assert_eq!(function_fqn!(), "rivia::core::tests::test_function_fqn_macro");
assert_eq!(indirect_fqn(), "rivia::core::tests::test_function_fqn_macro::indirect_fqn");
}
#[test]
fn test_function_macro()
{
fn indirect_func_name() -> &'static str
{
function!()
}
assert_eq!(function!(), "test_function_macro");
assert_eq!(indirect_func_name(), "indirect_func_name");
}
#[test]
fn test_trying_macro()
{
fn trying_func<T: AsRef<Path>>(path: T) -> Option<RvResult<PathBuf>>
{
Some(Ok(trying!(Stdfs::abs(path.as_ref()))))
}
assert_eq!(trying_func("").unwrap().unwrap_err().to_string(), "path empty");
}
}