1//! Private macro used for error handling.
2
3/// Logs an error, ignores an `Ok` value.
4macro_rules! log_if_err {
5 ($x:expr) => {
6 let closure = || {
7 try_else_return!($x);
8 };
9 closure();
10 };
11}
12
13/// Matches a result, returning the `Ok` value in case of success,
14/// exits the calling function otherwise.
15/// A closure which returns the return value for the function can
16/// be passed as second parameter.
17macro_rules! try_else_return {
18 ($x:expr) => {
19 try_else_return!($x, || {})
20 };
21 ($x:expr, $el:expr) => {
22 match $x {
23 Ok(x) => x,
24 Err(e) => {
25 crate::error::log_error(&e);
26 let closure = $el;
27 return closure();
28 }
29 }
30 };
31}
32
33/// Print an error message to stdout. Format is the same as println! or format!
34macro_rules! error {
35 ($($arg:tt)*) => (
36 println!("Criterion.rs ERROR: {}", &format!($($arg)*))
37 )
38}
39
40/// Print a debug message to stdout. Format is the same as println! or format!
41macro_rules! info {
42 ($($arg:tt)*) => (
43 if $crate::debug_enabled() {
44 println!("Criterion.rs DEBUG: {}", &format!($($arg)*))
45 }
46 )
47}
48