Expand description
A dependency-free macro library for verbose and debug printing in Rust.
§Introduction
I usually use log
with all log levels for printing,
but some people prefer to use just the --verbose
and --debug
flags.
For this reason, I created this library to provide a simple way to print verbose and debug messages
without the need for any dependencies or setup to the log
crate.
The library just provides the verbose!
and debug!
macros, which have the same syntax as println!
and prints only if the flags for them are set.
§Getting Started
Add the following to your Cargo.toml
:
[dependencies]
verbose-macros = "0.1"
Then, you can use the macros in your code:
use verbose_macros::{debug, verbose};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let verbose = std::env::args().any(|arg| arg == "--verbose" || arg == "-v");
let debug = std::env::args().any(|arg| arg == "--debug" || arg == "-d");
// Set the debug and verbose flags
verbose_macros::set_debug(verbose);
verbose_macros::set_verbose(debug);
// Use the debug macro
debug!("This is a debug message.");
debug!("This is a debug message with a value: {}", 42);
// Use the verbose macro
verbose!("This is a verbose message.");
verbose!("This is a verbose message with a value: {}", 42);
Ok(())
}
Macros§
Functions§
- is_
debug - Check if the debug flag is set.
- is_
verbose - Check if the verbose flag is set.
- set_
debug - Set the debug flag.
- set_
verbose - Set the verbose flag.
- try_
set_ debug - Safe version of
set_debug
that returns an error if the debug flag is already set. - try_
set_ verbose - Safe version of
set_verbose
that returns an error if the verbose flag is already set.