resext
Main crate providing error handling with context chains
This is the primary interface for ResExt. It re-exports the proc-macro as well as other helpers provided by ResExt.
Installation
[]
= "1.0.0"
Quick Example
use resext;
use ctx;
Proc Macro
The proc macro provides clean syntax with full customization:
Attribute Options
prefix- String prepended to entire error messagesuffix- String appended to entire error messagemsg_prefix- String prepended to each context messagemsg_suffix- String appended to each context messagedelimiter- Separator between context messages (default: "\n - ")source_prefix- String prepended to source error (default: "Error: ")include_variant- Include variant name in Display output (default: false)alias- Custom type alias name which is used for getting the names for other items generated by the proc-macro (default:Res)buf_size- Size for the context message byte buffer (default: 64)allocEnable heap-spilling if context exceedsbuf_size
.context() Method
Add static context to an error.
Accepts &str or ctx!() macro which outputs a lazily evaluated closure with usage similar to old format_args!() API
Example
read
.context?;
ctx!() macro
Macro defined in resext crate that returns a lazily evaluated closure with similar usage to old format_args!() context API but with better performance
- This macro shoudln't be used alone and should be used with
.context()method instead
Example
let path: &str = "file.txt";
read
.context?;
Error Display Format
Errors are displayed with context chains:
Failed to load application
- Failed to read config file
- Failed to open file
Error: No such file or directory
With include_variant = true:
Failed to load application
- Failed to read config file
Error: Io: No such file or directory
Examples
Error Handling
use ctx;
use resext;
use ;
Multiple Error Types
use resext;
async
Named Fields
use resext;
Contributing
See CONTRIBUTING.md for guidelines.
License
MIT - See LICENSE for details.