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;
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: " - " (NOTE: the delimiter always includes a newline before it, e.g. if delimiter = " - ", then messages will have "\n - " between them, not just " - ")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 Methods
.context(self, msg: &str)
Add static context to an error:
read
.context?;
Ok::
.with_context(self, args: core::fmt::Arguments<'_>)
Add dynamic context to an error:
let path = "file.txt";
read
.with_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
Basic Error Handling
Multiple Error Types
async
Named Fields
Contributing
See CONTRIBUTING.md for guidelines.
License
MIT - See LICENSE for details.