dynerr
Some macros to help with dynamic error handling/logging.
The goal of this crate is to unify all error types without compromising type safety.
The main features of this crate are the dynerr! and dynmatch! macros. when used alongside the return type DynResult<T>, they allows you to return multiple error types from a function then easily match for them during your error handling. Using dynerr, theres no need to ever wrap errors.
DynResult<T> is just an alias for Result<T, Box<dyn error::Error>> so anything that works on a Result<T> will still work on a DynResult<T>.
Dynerr works with any error type from any crate, as long as the type being returned implements std::error::Error then DynResult<T> should be able to handle it.
To directly return a custom error its recommended to use the dynerr! macro instead of Err().
To match against the dynamic error contained in DynResult<T>, use the dynmatch! macro.
dynmatch! usage looks similar to this:
let i = match example ;
Aside from its main features, dynerr also has some simple macros to help with lazy logging.
log! will log an event to the supplied file. Defaults to event.log if no log file supplied.
logged_panic! will log an event to file then panic. Defaults to event.log if no log file supplied.
check! will call .unwrap_or_else(|e| logged_panic!(e)) on a result. Defaults to event.log if no log file supplied.
If the supplied file doesn't exist then these macros will attempt to create the file.
These macros all rely on the log function. log is capable of panicking but shouldn't ever need to under normal circumstances.
A complete example:
use *;
use ;
//THIS SECTION IS CREATING THE FIRST CUSTOM ERROR
///a custom error type
//impl display formatting for error
//impl error conversion for error
//THIS SECTION IS CREATING THE SECOND CUSTOM ERROR
///THIS SECTION IS USING IT
///shows error handling capabilities using DynError