cdumay_error_derive
The cdumay_error_derive crate provides procedural macros to simplify the creation of custom error types in Rust. By leveraging these macros,
developers can efficiently define error structures that integrate seamlessly with the cdumay_error error management ecosystem.
Overview
Error handling in Rust often involves creating complex structs to represent various error kinds and implementing traits to provide context and
conversions. The cdumay_error_derive crate automates this process by offering macros that generate the necessary boilerplate code, allowing for
more readable and maintainable error definitions.
Features
- Macros: Automatically generate implementations for custom error types.
- Integration with cdumay_error: Designed to work cohesively with the
cdumay_errorcrate, ensuring consistent error handling patterns.
Usage
To utilize cdumay_error_derive in your project, follow these steps:
- Add Dependencies: Include
cdumay_errorwith the featurederivein yourCargo.toml:
[]
= { = "1.0", = ["derive"] }
- Define Error: Use the provided derive macros to define your error and error kind structs:
use ;
define_kinds!
define_errors!
In this example:
- define_kinds create
cdumay_error::ErrorKindstructs representing different categories of errors. - define_errors create
cdumay_error::Errorstruct that contains an ErrorKind and metadata.
- Implementing Error Handling: With the above definitions, you can now handle errors in your application as follows:
use File;
use Read;
This will output:
[Err-00001] Client::IoError::FileNotExists (400) - No such file or directory (os error 2)