pub trait HttpResponse {
// Required methods
fn to_result(self) -> Result<Response<Body>, HttpError>;
fn response_metadata() -> ApiEndpointResponse;
fn status_code(&self) -> StatusCode;
}
Expand description
HttpResponse must produce a Result<Response<Body>, HttpError>
and generate
the response metadata. Typically one should use Response<Body>
or an
implementation of HttpTypedResponse
.
Required Methods§
Sourcefn to_result(self) -> Result<Response<Body>, HttpError>
fn to_result(self) -> Result<Response<Body>, HttpError>
Generate the response to the HTTP call.
Sourcefn response_metadata() -> ApiEndpointResponse
fn response_metadata() -> ApiEndpointResponse
Extract status code and structure metadata for the non-error response. Type information for errors is handled generically across all endpoints.
Sourcefn status_code(&self) -> StatusCode
fn status_code(&self) -> StatusCode
Extract the status code from the concrete response instance.
This may differ from the value extracted from response_metadata()
in
error cases or if one has built a response manually using something like
Response<Body>
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl HttpResponse for Response<Body>
Response<Body>
is used for free-form responses. The implementation of
to_result()
is trivial, and we don’t have any typed metadata to return.
impl HttpResponse for Response<Body>
Response<Body>
is used for free-form responses. The implementation of
to_result()
is trivial, and we don’t have any typed metadata to return.
fn to_result(self) -> Result<Response<Body>, HttpError>
fn response_metadata() -> ApiEndpointResponse
fn status_code(&self) -> StatusCode
Implementors§
impl<T> HttpResponse for Twhere
T: HttpCodedResponse,
Provide results and metadata generation for all implementing types.