Skip to content

Commit

Permalink
provide StaticResponseFactory: to make custom response for ConsumeErr…
Browse files Browse the repository at this point in the history
… easy

in future we might also want to allow a response function, but
for now not needed. Open to feature requests or
PRs for it
  • Loading branch information
GlenDC committed Aug 19, 2024
1 parent 0b3eca5 commit 0a81946
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/http/response/into_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ pub trait IntoResponse {
fn into_response(self) -> Response;
}

/// Wrapper that can be used to turn an `IntoResponse` type into
/// something that implements Into<Response>.
pub struct StaticResponseFactory<T>(pub T);

impl<T: IntoResponse> From<StaticResponseFactory<T>> for Response {
fn from(value: StaticResponseFactory<T>) -> Self {
value.0.into_response()
}
}

impl<T: fmt::Debug> fmt::Debug for StaticResponseFactory<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("StaticResponseFactory")
.field(&self.0)
.finish()
}
}

impl<T: Clone> Clone for StaticResponseFactory<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}

impl IntoResponse for StatusCode {
fn into_response(self) -> Response {
let mut res = ().into_response();
Expand Down

0 comments on commit 0a81946

Please sign in to comment.