simplify macros

This commit is contained in:
Harald Hoyer 2019-03-04 11:37:34 +01:00
parent 2f8c68b36d
commit 8bd4ffca56
No known key found for this signature in database
GPG key ID: 340F12141EA0994D

View file

@ -684,15 +684,9 @@ macro_rules! cherr {
( None, $fmt:expr, $($arg:tt)+ ) => ({ ( None, $fmt:expr, $($arg:tt)+ ) => ({
cherr!(None, format!($fmt, $($arg)+ )) cherr!(None, format!($fmt, $($arg)+ ))
}); });
( $e:ident, $k:expr ) => ({
ChainError::<_>::new($k, Some(Box::from($e)), Some((line!(), file!())))
});
( $e:path, $k:expr ) => ({ ( $e:path, $k:expr ) => ({
ChainError::<_>::new($k, Some(Box::from($e)), Some((line!(), file!()))) ChainError::<_>::new($k, Some(Box::from($e)), Some((line!(), file!())))
}); });
( $e:ident, $fmt:expr, $($arg:tt)+ ) => ({
cherr!($e, format!($fmt, $($arg)+ ))
});
( $e:path, $fmt:expr, $($arg:tt)+ ) => ({ ( $e:path, $fmt:expr, $($arg:tt)+ ) => ({
cherr!($e, format!($fmt, $($arg)+ )) cherr!($e, format!($fmt, $($arg)+ ))
}); });
@ -787,21 +781,12 @@ macro_rules! cherr {
/// ~~~ /// ~~~
#[macro_export] #[macro_export]
macro_rules! mstrerr { macro_rules! mstrerr {
( $t:ident, $msg:expr ) => ({
|e| cherr!(e, $t ($msg.to_string()))
});
( $t:path, $msg:expr ) => ({ ( $t:path, $msg:expr ) => ({
|e| cherr!(e, $t ($msg.to_string())) |e| cherr!(e, $t ($msg.to_string()))
}); });
( $t:ident, $msg:expr, ) => ({
|e| cherr!(e, $t ($msg.to_string()))
});
( $t:path, $msg:expr, ) => ({ ( $t:path, $msg:expr, ) => ({
|e| cherr!(e, $t ($msg.to_string())) |e| cherr!(e, $t ($msg.to_string()))
}); });
( $t:ident, $fmt:expr, $($arg:tt)+ ) => ({
|e| cherr!(e, $t (format!($fmt, $($arg)+ )))
});
( $t:path, $fmt:expr, $($arg:tt)+ ) => ({ ( $t:path, $fmt:expr, $($arg:tt)+ ) => ({
|e| cherr!(e, $t (format!($fmt, $($arg)+ ))) |e| cherr!(e, $t (format!($fmt, $($arg)+ )))
}); });
@ -854,21 +839,12 @@ macro_rules! mstrerr {
/// ~~~ /// ~~~
#[macro_export] #[macro_export]
macro_rules! strerr { macro_rules! strerr {
( $t:ident, $msg:expr ) => ({
cherr!($t ($msg.to_string()))
});
( $t:path, $msg:expr ) => ({ ( $t:path, $msg:expr ) => ({
cherr!($t ($msg.to_string())) cherr!($t ($msg.to_string()))
}); });
( $t:ident, $msg:expr, ) => ({
cherr!($t ($msg.to_string()))
});
( $t:path, $msg:expr, ) => ({ ( $t:path, $msg:expr, ) => ({
cherr!($t ($msg.to_string())) cherr!($t ($msg.to_string()))
}); });
( $t:ident, $fmt:expr, $($arg:tt)+ ) => ({
cherr!($t (format!($fmt, $($arg)+ )))
});
( $t:path, $fmt:expr, $($arg:tt)+ ) => ({ ( $t:path, $fmt:expr, $($arg:tt)+ ) => ({
cherr!($t (format!($fmt, $($arg)+ ))) cherr!($t (format!($fmt, $($arg)+ )))
}); });