Add support for returning pretty JSON response in axum_extra::response::ErasedJson (#662)

This commit is contained in:
Guy Lapid
2021-12-28 09:19:24 +00:00
committed by GitHub
parent 4fd7e927ba
commit d602682821
2 changed files with 8 additions and 1 deletions
+6 -1
View File
@@ -33,10 +33,15 @@ use serde::Serialize;
pub struct ErasedJson(serde_json::Result<Vec<u8>>);
impl ErasedJson {
/// Create an `ErasedJson` by serializing a value.
/// Create an `ErasedJson` by serializing a value with the compact formatter.
pub fn new<T: Serialize>(val: T) -> Self {
Self(serde_json::to_vec(&val))
}
/// Create an `ErasedJson` by serializing a value with the pretty formatter.
pub fn pretty<T: Serialize>(val: T) -> Self {
Self(serde_json::to_vec_pretty(&val))
}
}
impl IntoResponse for ErasedJson {