mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-05 08:08:15 -07:00
snapshot
This commit is contained in:
@@ -3,6 +3,7 @@ use axum::{
|
||||
http::{Response, StatusCode},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
||||
use super::header_map::HeaderMapExtended;
|
||||
|
||||
@@ -13,10 +14,10 @@ where
|
||||
fn new_not_modified() -> Self;
|
||||
fn new_json<T>(value: T, etag: &str) -> Self
|
||||
where
|
||||
T: sonic_rs::Serialize;
|
||||
T: Serialize;
|
||||
fn new_json_with<T>(status: StatusCode, value: T, etag: &str) -> Self
|
||||
where
|
||||
T: sonic_rs::Serialize;
|
||||
T: Serialize;
|
||||
}
|
||||
|
||||
impl ResponseExtended for Response<Body> {
|
||||
@@ -29,16 +30,16 @@ impl ResponseExtended for Response<Body> {
|
||||
|
||||
fn new_json<T>(value: T, etag: &str) -> Self
|
||||
where
|
||||
T: sonic_rs::Serialize,
|
||||
T: Serialize,
|
||||
{
|
||||
Self::new_json_with(StatusCode::default(), value, etag)
|
||||
}
|
||||
|
||||
fn new_json_with<T>(status: StatusCode, value: T, etag: &str) -> Self
|
||||
where
|
||||
T: sonic_rs::Serialize,
|
||||
T: Serialize,
|
||||
{
|
||||
let bytes = sonic_rs::to_vec(&value).unwrap();
|
||||
let bytes = serde_json::to_vec(&value).unwrap();
|
||||
let mut response = Response::builder().body(bytes.into()).unwrap();
|
||||
*response.status_mut() = status;
|
||||
let headers = response.headers_mut();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use axum::{http::StatusCode, response::Response};
|
||||
use brk_error::{Error, Result};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::extended::ResponseExtended;
|
||||
|
||||
@@ -7,7 +8,7 @@ pub trait ResultExtended<T> {
|
||||
fn with_status(self) -> Result<T, (StatusCode, String)>;
|
||||
fn to_json_response(self, etag: &str) -> Response
|
||||
where
|
||||
T: sonic_rs::Serialize;
|
||||
T: Serialize;
|
||||
}
|
||||
|
||||
impl<T> ResultExtended<T> for Result<T> {
|
||||
@@ -29,7 +30,7 @@ impl<T> ResultExtended<T> for Result<T> {
|
||||
|
||||
fn to_json_response(self, etag: &str) -> Response
|
||||
where
|
||||
T: sonic_rs::Serialize,
|
||||
T: Serialize,
|
||||
{
|
||||
match self.with_status() {
|
||||
Ok(value) => Response::new_json(&value, etag),
|
||||
|
||||
Reference in New Issue
Block a user