This library provides an ergonomic experience of adding debugging messages to rust's
Result<T,E>
and Option<T>
patterns
Just like the cli-toolbox
crate, that the debug logic
is based on, this is not a logging alternative; it's intended to produce debugging output to be
used during application development.
Although the macros were designed to make debugging more ergonomic, they include variations that do not include debugging to provide coding consistency, so you have the option use the same syntax consistently throughout your crate.
Result<T,E>
```rust use std::fs::File; use std::io; use std::io::{BufWriter, Write};
use macrofied_toolbox::result;
use cli_toolbox::debug;
fn main() -> io::Result<()> { let file_name = "foo.txt";
// attempts to create a file
result! {
WHEN File::create(file_name);
// if the file is successfully created, write some content
OK file; {
let mut out = BufWriter::new(file);
writeln!(out, "some content")?;
writeln!(out, "some more content")?;
}
// if an exception occurs output debug message to stderr
DEBUG "problem creating file: {:?}", file_name
// * debug messages are conditionally compiled
// and do not output anything in release builds
// * exceptions are appended to the debug message
};
Ok(())
} ```
Option<T>
.
.
.
* the macros are automatically generated with custom build scripts, including their docs
and tests
Each macro is gated by a feature.
No feature is mutually exclusive and can be combined as needed.
toml
[dependencies]
macrofied-toolbox = { version = "0.1", features = ["option", "result"] }
macrofied-toolbox
can optionally use the cli-toolbox
crate to output
debug to the console by enabling an of these features
debug-all
- enables console debugging for all the features enableddebug-option
- enables console debugging for the option!
macrodebug-result
- enables console debugging for the result!
macrooption!
- handles an Option<T>
of an expressionresult!
Ok<t>
value through?
syntaxOk<T>
valuesOk<T>
valuesOk<T>
and Err<E>
result!
- handles a Result<T,E>
of an expression