Info Utils
Utilities for logging and error-handling in Rust.
Features
-
log!
,warn!
, anderror!
macros for convenient and informational data display -
eval()
as a drop in forunwrap()
-
should()
as a drop in forexpect()
-
Info Utils also provides
eval_or()
,eval_or_default()
, andeval_or_else()
functions as drop-ins for the correspondingunwrap_*()
functions.
Usage
Add the following to your cargo.toml
:
[]
= "2"
Or run
Use in Rust Code
Macros
Basic Use
use *;
Output
❯ cargo run
Compiling demo v0.1.0 (/Path/To/Project)
Finished dev [unoptimized + debuginfo] target(s) in 0.15s
Running `target/debug/demo`
info ["main"]: Value is 10
warn ["main"]: 10 is greater than 3
error ["main"]: x is equal to 10, exiting..
Terminal output is color formatted
With Named Threads
use *;
use thread;
Output
❯ cargo run
Compiling demo v0.1.0 (/Path/To/Project)
Finished dev [unoptimized + debuginfo] target(s) in 0.15s
Running `target/debug/demo`
info ["main"]: Hello from main thread!
info ["named thread"]: Hello from inside a named thread!
info ["<unknown>"]: Hello from inside an unnamed thread!
Eval
Basic Use
use *;
Output
❯ cargo run
Compiling demo v0.1.0 (/Path/To/Project)
Finished dev [unoptimized + debuginfo] target(s) in 0.15s
Running `target/debug/demo`
info ["main"]: Option: valid value - Value: everything's fine
error ["main"]: "oh no something happened!"
Other Functions
use *;
Output
❯ cargo run
Compiling demo v0.1.0 (/Path/To/Project)
Finished dev [unoptimized + debuginfo] target(s) in 0.15s
Running `target/debug/demo`
info ["main"]: Option: valid value - Value: everything's fine
info ["main"]: Result: it's alright we can handle this
warn ["main"]: Option: option was None
info ["main"]: Result:
warn ["main"]: error was: "oh no something happened!", but we're all good anyways
info ["main"]: Result: error handled
Contributing
If you notice any issues or bugs in the package or docs please create an issue or PR addressing it.
Also feel free to file issues for feature requests.