mirror of
https://github.com/haraldh/chainerror.git
synced 2025-01-31 00:56:41 +01:00
refine macros
This commit is contained in:
parent
ee9bd65af6
commit
7003baaaec
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "chainerror"
|
name = "chainerror"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
authors = ["Harald Hoyer <harald@redhat.com>"]
|
authors = ["Harald Hoyer <harald@redhat.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
|
63
src/lib.rs
63
src/lib.rs
|
@ -665,6 +665,9 @@ macro_rules! cherr {
|
||||||
( $k:expr ) => {
|
( $k:expr ) => {
|
||||||
ChainError::<_>::new($k, None, Some((line!(), file!())))
|
ChainError::<_>::new($k, None, Some((line!(), file!())))
|
||||||
};
|
};
|
||||||
|
( None, $k:expr ) => {
|
||||||
|
ChainError::<_>::new($k, None, Some((line!(), file!())))
|
||||||
|
};
|
||||||
( $e:expr, $k:expr ) => {
|
( $e:expr, $k:expr ) => {
|
||||||
ChainError::<_>::new($k, Some(Box::from($e)), Some((line!(), file!())))
|
ChainError::<_>::new($k, Some(Box::from($e)), Some((line!(), file!())))
|
||||||
};
|
};
|
||||||
|
@ -759,15 +762,27 @@ fn func1() -> Result<(), Box<Error>> {
|
||||||
**/
|
**/
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! mstrerr {
|
macro_rules! mstrerr {
|
||||||
( $t:ident, $v:expr $(, $more:expr)* ) => {
|
( $t:ident, $msg:expr ) => ({
|
||||||
|e| cherr!(e, $t (format!($v, $( $more , )* )))
|
|e| cherr!(e, $t ($msg.to_string()))
|
||||||
};
|
});
|
||||||
( $t:path, $v:expr $(, $more:expr)* ) => {
|
( $t:path, $msg:expr ) => ({
|
||||||
|e| cherr!(e, $t (format!($v, $( $more , )* )))
|
|e| cherr!(e, $t ($msg.to_string()))
|
||||||
};
|
});
|
||||||
( $v:expr $(, $more:expr)* ) => {
|
( $t:ident, $fmt:expr, $($arg:tt)+ ) => ({
|
||||||
|e| cherr!(e, format!($v, $( $more , )* ))
|
|e| cherr!(e, $t (format!($fmt, $($arg)+ )))
|
||||||
};
|
});
|
||||||
|
( $t:path, $fmt:expr, $($arg:tt)+ ) => ({
|
||||||
|
|e| cherr!(e, $t (format!($fmt, $($arg)+ )))
|
||||||
|
});
|
||||||
|
($msg:expr) => ({
|
||||||
|
|e| cherr!(e, $msg.to_string())
|
||||||
|
});
|
||||||
|
($msg:expr, ) => ({
|
||||||
|
|e| cherr!(e, $msg.to_string())
|
||||||
|
});
|
||||||
|
($fmt:expr, $($arg:tt)+) => ({
|
||||||
|
|e| cherr!(e, format!($fmt, $($arg)+ ))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** convenience macro for cherr!(T(format!(…))) where T(String)
|
/** convenience macro for cherr!(T(format!(…))) where T(String)
|
||||||
|
@ -807,15 +822,27 @@ fn func1() -> Result<(), Box<Error>> {
|
||||||
**/
|
**/
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! strerr {
|
macro_rules! strerr {
|
||||||
( $t:ident, $v:expr $(, $more:expr)* ) => {
|
( $t:ident, $msg:expr ) => ({
|
||||||
cherr!($t (format!($v, $( $more , )* )))
|
cherr!($t ($msg.to_string()))
|
||||||
};
|
});
|
||||||
( $t:path, $v:expr $(, $more:expr)* ) => {
|
( $t:path, $msg:expr ) => ({
|
||||||
cherr!($t (format!($v, $( $more , )* )))
|
cherr!($t ($msg.to_string()))
|
||||||
};
|
});
|
||||||
( $v:expr $(, $more:expr)* ) => {
|
( $t:ident, $fmt:expr, $($arg:tt)+ ) => ({
|
||||||
cherr!(format!($v, $( $more , )* ))
|
cherr!($t (format!($fmt, $($arg)+ )))
|
||||||
};
|
});
|
||||||
|
( $t:path, $fmt:expr, $($arg:tt)+ ) => ({
|
||||||
|
cherr!($t (format!($fmt, $($arg)+ )))
|
||||||
|
});
|
||||||
|
($msg:expr) => ({
|
||||||
|
cherr!($msg.to_string())
|
||||||
|
});
|
||||||
|
($msg:expr, ) => ({
|
||||||
|
cherr!($msg.to_string())
|
||||||
|
});
|
||||||
|
($fmt:expr, $($arg:tt)+) => ({
|
||||||
|
cherr!(format!($fmt, $($arg)+ ))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** convenience macro to create a "new type" T(String) and implement Display + Debug for T
|
/** convenience macro to create a "new type" T(String) and implement Display + Debug for T
|
||||||
|
|
Loading…
Reference in a new issue