Crates.io | axum-enum-response |
lib.rs | axum-enum-response |
version | 0.2.0 |
source | src |
created_at | 2024-02-28 19:12:27.571755 |
updated_at | 2024-08-26 09:13:32.39495 |
description | Easily create axum::http::Response's from Enums! |
homepage | |
repository | https://github.com/lillianrubyrose/axum-enum-response |
max_upload_size | |
id | 1156858 |
size | 25,599 |
MSRV: 1.65.0
Easily create axum::http::Response's from Enums!
#[derive(serde::Serialize)]
struct SomeData {
meow: String,
}
enum ErrorResponse {
#[status_code(UNAUTHORIZED)]
Unauthorized, // 401, empty body
#[status_code(OK)]
#[body("hello"=>"world")]
Ok, // 200, body = {"hello": "world"}
#[status_code(FORBIDDEN)]
#[body("mew")]
Forbidden, // 403, body = {"error": "mew"}
#[status_code(INTERNAL_SERVER_ERROR)]
FromUtf8Error(#[from] FromUtf8Error), // 500, body = {"error": FromUtf8Error::to_string()}
#[status_code(INTERNAL_SERVER_ERROR)]
InternalServerError(#[key("awwa")] String), // 500, body = {"awwa": STRING}
}