pub struct ErasedJson(/* private fields */);
Available on crate feature
erased-json
only.Expand description
A response type that holds a JSON in serialized form.
This allows returning a borrowing type from a handler, or returning different response types as JSON from different branches inside a handler.
Like [axum::Json
],
if the Serialize
implementation fails
or if a map with non-string keys is used,
a 500 response will be issued
whose body is the error message in UTF-8.
This can be constructed using new
or the json!
macro.
§Example
async fn handler() -> ErasedJson {
// ...
if condition {
ErasedJson::new(&foo)
} else {
ErasedJson::new(&bar)
}
}
Implementations§
Trait Implementations§
Source§impl Clone for ErasedJson
impl Clone for ErasedJson
Source§fn clone(&self) -> ErasedJson
fn clone(&self) -> ErasedJson
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ErasedJson
impl Debug for ErasedJson
Source§impl IntoResponse for ErasedJson
impl IntoResponse for ErasedJson
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.
Auto Trait Implementations§
impl !Freeze for ErasedJson
impl !RefUnwindSafe for ErasedJson
impl Send for ErasedJson
impl Sync for ErasedJson
impl Unpin for ErasedJson
impl !UnwindSafe for ErasedJson
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Call the handler with the given request.
Source§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
Apply a
tower::Layer
to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Convert the handler into a
Service
by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Convert the handler into a
Service
and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
Convert the handler into a
MakeService
and no state. Read more