use axum::response::{IntoResponse, Response}; use serde::Serialize; use serde_json::json; pub enum ApiResponse { Success(T), Fail(T), Error(String), } impl IntoResponse for ApiResponse where T: Serialize, { fn into_response(self) -> Response { axum::Json(match self { ApiResponse::Success(data) => json!({ "status": "success", "data": data }), ApiResponse::Fail(data) => json!({ "status": "fail", "data": data }), ApiResponse::Error(message) => json!({ "status": "error", "message": message }), }) .into_response() } }