apiresponse-macro
Derive macro for the apiresponse crate. Implements the Response trait automatically for your error enums.
Usage
use Response;
use Error;
Variant-level Attributes
| Attribute | Required | Description |
|---|---|---|
#[response(code = N)] |
Yes* | Error code for this variant |
#[response(status = N)] |
No | HTTP status code (default: 200) |
#[response(transparent)] |
— | Delegate to inner error's Response impl |
* Not needed on transparent variants — they delegate to the inner error.
Generated Implementation
The macro generates a Response impl with three methods:
error_code()— returns thecodevalue (or delegates to inner error fortransparent)message()— delegates toDisplay(i.e., your#[error("...")]message)http_status_code()— returns thestatusvalue (or delegates to inner error fortransparent)
Requirements
apiresponse >= 0.2.1
syn+quote+proc-macro2(for proc-macro compilation)
License
MIT OR Apache-2.0