Try Warn
This crate provides a means of propagating non critical warning states, backed by an underlying Logger implementation to control when warnings are logged, ignored, or a fatal issue when the priorities of a crate developer, and a crate's user aren't aligned on what they consider critical error, or acceptable warnings.
The goal of this crate is also to distinguish debug, and release builds in terms of warning and error severity to allow for more rapid prototyping without compromising quality of code in release builds, and hopefully helping to deminish the learning curve of rust a bit (similar to the motivations behind anyhow).
How it works:
This crate provides the Warnable type, a wrapper around a value that may
have associated non-fatal warnings. The warnings can be automatically logged
via a Logger implementation, propagated manually, or ignored.
Features:
- Attach warnings to a value without failing.
- Automatic logging in debug builds and in
Drop. - Optional manual propagation of warnings via
propagate()orunwrap(). - Works with custom logging mechanisms.
Macro Example
use ;
use fmt;
;
let mut warning = warninit!;
warn!;
// only shows the warning/info message on debug builds
info!;
let warnable = ret!;
// unwraps logging any warnings to StdErr (default logger).
let message = warnable.unwrap;
Manual Example
use ;
use fmt;
;
let wrapped = warning;
let value = wrapped.unwrap; // logs warning and returns 42
assert_eq!;
Future Plans
- Handle logger trait error handling cleanly.
- Move unwrap to flush, implement unwrap as a panic fn.
- Implement expect.