From 6ad94975125fd72b0590bf3a6ef03bbc143314fe Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Wed, 9 Jan 2019 13:22:49 +0100 Subject: [PATCH] extend cherr! macro --- Cargo.toml | 2 +- src/lib.rs | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d02f463..4b4d99d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chainerror" -version = "0.3.2" +version = "0.4.0" authors = ["Harald Hoyer "] edition = "2018" license = "MIT/Apache-2.0" diff --git a/src/lib.rs b/src/lib.rs index 89af31e..09df831 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -662,15 +662,31 @@ fn func() -> ChainResult<(), FooError> { **/ #[macro_export] macro_rules! cherr { - ( $k:expr ) => { + ( $k:expr ) => ({ ChainError::<_>::new($k, None, Some((line!(), file!()))) - }; - ( None, $k:expr ) => { + }); + ( None, $k:expr ) => ({ ChainError::<_>::new($k, None, Some((line!(), file!()))) - }; - ( $e:expr, $k:expr ) => { + }); + ( None, $fmt:expr, $($arg:tt)+ ) => ({ + cherr!(None, format!($fmt, $($arg)+ )) + }); + ( None, $fmt:expr, $($arg:tt)+ ) => ({ + cherr!(None, format!($fmt, $($arg)+ )) + }); + ( $e:ident, $k:expr ) => ({ ChainError::<_>::new($k, Some(Box::from($e)), Some((line!(), file!()))) - }; + }); + ( $e:path, $k:expr ) => ({ + 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)+ ) => ({ + cherr!($e, format!($fmt, $($arg)+ )) + }); + } /** convenience macro for |e| cherr!(e, format!(…)) @@ -768,6 +784,12 @@ macro_rules! mstrerr { ( $t:path, $msg:expr ) => ({ |e| cherr!(e, $t ($msg.to_string())) }); + ( $t:ident, $msg:expr, ) => ({ + |e| cherr!(e, $t ($msg.to_string())) + }); + ( $t:path, $msg:expr, ) => ({ + |e| cherr!(e, $t ($msg.to_string())) + }); ( $t:ident, $fmt:expr, $($arg:tt)+ ) => ({ |e| cherr!(e, $t (format!($fmt, $($arg)+ ))) }); @@ -828,6 +850,12 @@ macro_rules! strerr { ( $t:path, $msg:expr ) => ({ cherr!($t ($msg.to_string())) }); + ( $t:ident, $msg:expr, ) => ({ + cherr!($t ($msg.to_string())) + }); + ( $t:path, $msg:expr, ) => ({ + cherr!($t ($msg.to_string())) + }); ( $t:ident, $fmt:expr, $($arg:tt)+ ) => ({ cherr!($t (format!($fmt, $($arg)+ ))) });