kamu_snap_response_axum/
lib.rs1#![forbid(unsafe_code)]
9
10use axum::{Json, response::IntoResponse};
11use kamu_snap_response::SnapResponse;
12use serde::Serialize;
13
14pub struct AxumResponder<T>(pub SnapResponse<T>);
17
18impl<T: Serialize> IntoResponse for AxumResponder<T> {
19 fn into_response(self) -> axum::response::Response {
20 let status = self.0.envelope.response_code.http().unwrap_or(http::StatusCode::INTERNAL_SERVER_ERROR);
21 (status, Json(self.0)).into_response()
22 }
23}
24
25pub trait SnapResponderExt<T> {
27 fn into_axum(self) -> AxumResponder<T>;
29}
30
31impl<T> SnapResponderExt<T> for SnapResponse<T> {
32 fn into_axum(self) -> AxumResponder<T> {
33 AxumResponder(self)
34 }
35}