pub struct Json(/* private fields */);
Expand description
A Response
body with Content-Type
set to
application/json
.
§Example
use pavex::response::{Response, body::Json};
use pavex::http::header::CONTENT_TYPE;
#[derive(serde::Serialize)]
struct HomeDetails {
city: String,
postcode: String,
}
let details = HomeDetails {
city: "London".into(),
postcode: "N5 2EF".into(),
};
let json = Json::new(details).expect("Failed to serialize the response body");
let response = Response::ok().set_typed_body(json);
assert_eq!(response.headers()[CONTENT_TYPE], "application/json");
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Json
impl RefUnwindSafe for Json
impl Send for Json
impl Sync for Json
impl Unpin for Json
impl UnwindSafe for Json
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more