nobug 0.7.0

Assertions and active code annotations
Documentation
/// Prints an critical message to stderr. Critical means that the program is in an undefined
/// state and going to abort.
///
/// # Arguments
///
/// * `fmt`  - a sequence of tokens within parenthesis that are concat!()'ed to form a format string
///            or a literal string.
/// * `args` - Optional comma separated Arguments for the message.
///
/// # Example
///
/// ```rust
/// # use nobug::*;
/// CRITICAL!("This is a critical message");
/// CRITICAL!("This is a critical message with arguments: {}", 42);
/// ```
#[macro_export]
macro_rules! CRITICAL {
    (($($fmt:tt)*) $(,$($args:expr),*)?) => {
        eprintln!(concat!(file!(), ":", line!(), ": ", $($fmt)*) $(,$($args),*)?)
    };
    ($fmt:literal $(,$($args:expr),*)?) => {
        eprintln!(concat!(file!(), ":", line!(), ": ", $fmt) $(,$($args),*)?)
    };
}

/// Prints a critical message only in debug mode.
///
/// # Example
///
/// ```rust
/// # use nobug::*;
/// CRITICAL_DBG!("This is a critical message");
/// CRITICAL_DBG!("This is a critical message with arguments: {}", 42);
/// ```
#[macro_export]
macro_rules! CRITICAL_DBG {
    ($($msg:tt)+) => {{
        #[cfg(debug_assertions)]
        $crate::CRITICAL!($($msg)+);
    }}
}

/// Prints a notice to stderr. Notices are only about notifying the user of something while the program
/// is running.
///
/// # Arguments
///
/// * `fmt`  - a sequence of tokens within parenthesis that are concat!()'ed to form a format string
///            or a literal string.
/// * `args` - Optional comma separated Arguments for the message.
/// * `expr` - Expression to print the value of. Must implement `Debug`.
///
/// # Example
///
/// ```rust
/// # use nobug::*;
/// NOTICE!("This is a notice");
/// NOTICE!("This is a notice with arguments: {}", 42);
/// NOTICE!(1+1);
/// ```
#[macro_export]
macro_rules! NOTICE {
    (($($fmt:tt)*) $(,$($args:expr),*)?) => {
        eprintln!(concat!(file!(), ":", line!(), ": ", $($fmt)*) $(,$($args),*)?)
    };
    ($fmt:literal $(,$($args:expr),*)?) => {
        eprintln!(concat!(file!(), ":", line!(), ": ", $fmt) $(,$($args),*)?)
    };
    ($expr:expr) => {
        eprintln!(concat!(file!(), ":", line!(), ": {} == {:?}" ), stringify!($expr), $expr)
    };
}

/// Prints a notice only in debug mode.
///
/// # Example
///
/// ```rust
/// # use nobug::*;
/// NOTICE_DBG!("This is a notice");
/// NOTICE_DBG!("This is a notice with arguments: {}", 42);
/// NOTICE_DBG!(1+1);
/// ```
#[macro_export]
macro_rules! NOTICE_DBG {
    ($($msg:tt)+) => {{
        #[cfg(debug_assertions)]
        $crate::NOTICE!($($msg)+);
    }}
}

/// Prints a trace message to stderr.
///
/// # Arguments
///
/// * `fmt`  - a sequence of tokens within parenthesis that are concat!()'ed to form a format string
///            or a literal string.
/// * `args` - Optional comma separated Arguments for the message.
/// * `expr` - Expression to print the value of. Must implement `Debug`.
///
/// These arguments are optional a single `TRACE!();` will just print "\<file\>:\<line\>: TRACEPOINT" which
/// comes handy when one just wants to debug the progress of a program.
///
/// # Example
///
/// ```rust
/// # use nobug::*;
/// TRACE!(); // prints "<file>:<line>: TRACEPOINT"
/// TRACE!("This is a trace message");
/// TRACE!("This is a trace message with arguments: {}", 42);
/// TRACE!(1+1);
/// ```
#[macro_export]
macro_rules! TRACE {
    (($($fmt:tt)*) $(,$($args:expr),*)?) => {
        eprintln!(concat!(file!(), ":", line!(), ": ", $($fmt)*) $(,$($args),*)?)
    };
    ($fmt:literal $(,$($args:expr),*)?) => {
        eprintln!(concat!(file!(), ":", line!(), ": ", $fmt) $(,$($args),*)?)
    };
    ($expr:expr) => {
        eprintln!(concat!(file!(), ":", line!(), ": {} == {:?}" ), stringify!($expr), $expr)
    };
    () => {
        eprintln!(concat!(file!(), ":", line!(), ": TRACEPOINT"))
    };
}

/// Prints a trace message only in debug mode.
///
/// # Example
///
/// ```rust
/// # use nobug::*;
/// TRACE_DBG!(); // prints "<file>:<line>: TRACEPOINT" in debug mode
/// TRACE_DBG!("This is a trace message");
/// TRACE_DBG!("This is a trace message with arguments: {}", 42);
/// TRACE_DBG!(1+1);
/// ```
#[macro_export]
macro_rules! TRACE_DBG {
    ($($msg:tt)*) => {{
        #[cfg(debug_assertions)]
        $crate::TRACE!($($msg)*)
    }}
}

/// Prints a trace message only in debug mode with and only when a conditional is `true`.
///
/// # Example
///
/// ```rust
/// # use nobug::*;
/// TRACE_DBG_IF!(true => "This is a conditional trace message with arguments: {}", 42);
/// TRACE_DBG_IF!(true => 1+1);
/// TRACE_DBG_IF!(true); // prints "<file>:<line>: TRACEPOINT" in debug mode with a conditional
/// ```
#[macro_export]
macro_rules! TRACE_DBG_IF {
    ($cond:expr => $($msg:tt)+) => {{
        #[cfg(debug_assertions)]
        if $cond {
            $crate::TRACE!($($msg)+)
        }
    }};
    ($cond:expr) => {{
        #[cfg(debug_assertions)]
        if $cond {
            $crate::TRACE!()
        }
    }};
}

/// Prints a notice only once to stderr. Used for printing annotations without cluttering the
/// output overly much.
///
/// # Arguments
///
/// * `fmt`  - a sequence of tokens within parenthesis that are concat!()'ed to form a format string
///            or a literal string.
/// * `args` - Optional comma separated Arguments for the message.
/// * `expr` - Optional expression to print the value of. Must implement `Debug`.
///
/// # Example
///
/// ```rust
/// # use nobug::*;
/// NOTICE_ONCE!("This is a notice");
/// NOTICE_ONCE!("This is a notice with arguments: {}", 42);
/// ```
#[macro_export]
macro_rules! NOTICE_ONCE {
    (($($fmt:tt)*) $(,$($args:expr),*)?) => {
        $crate::ONCE!(eprintln!(concat!(file!(), ":", line!(), ": ", $($fmt)*) $(,$($args),*)?))
    };
    ($fmt:literal $(,$($args:expr),*)?) => {
        $crate::ONCE!(eprintln!(concat!(file!(), ":", line!(), ": ", $fmt) $(,$($args),*)?))
    };
    ($expr:expr) => {
        $crate::ONCE!(eprintln!(concat!(file!(), ":", line!(), ": {} == {:?}" ), stringify!($expr), $expr))
    };
}

/// Prints a notice only once in debug mode.
#[macro_export]
macro_rules! NOTICE_ONCE_DBG {
    ($($msg:tt)+) => {{
        #[cfg(debug_assertions)]
        $crate::NOTICE_ONCE!($($msg)+);
    }}
}

/// Used to trace nobug itself.
#[doc(hidden)]
#[macro_export]
macro_rules! TRACE_NOBUG {
    ($($msg:tt)*) => {
        #[cfg(feature = "trace_nobug")]
        $crate::TRACE!($($msg)*);
    };
}