Skip to main content

Crate apiresponse_macro

Crate apiresponse_macro 

Source
Expand description

Derive macros for the apiresponse crate.

This crate provides the #[derive(Response)] macro which implements the Response trait for your error types.

§Usage with thiserror

use apiresponse::Response;
use thiserror::Error;

#[derive(Debug, Error, Response)]
pub enum MyError {
    #[error("not found")]
    #[response(code = 1001, status = 404)]
    NotFound,

    #[error("unauthorized: {0}")]
    #[response(code = 1002, status = 401)]
    Unauthorized(String),

    #[error(transparent)]
    #[response(transparent)]
    Other(#[from] anyhow::Error),
}

Derive Macros§

Response
Derive macro for implementing the Response trait.