Skip to content

Commit

Permalink
remove static requirements for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Nov 20, 2023
1 parent 6c40a0d commit 8775674
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions tower-async-http/_todo_examples/axum-key-value-store/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ fn app() -> Router {
.map_response_body(axum::body::boxed)
// Compress responses
.compression();
// Set a `Content-Type` if there isn't one already.
// .insert_response_header_if_not_present(
// header::CONTENT_TYPE,
// HeaderValue::from_static("application/octet-stream"),
// );
// Set a `Content-Type` if there isn't one already.
// .insert_response_header_if_not_present(
// header::CONTENT_TYPE,
// HeaderValue::from_static("application/octet-stream"),
// );

let router_layer = middleware.into_classic();

Expand Down
4 changes: 2 additions & 2 deletions tower-async-http/src/classify/grpc_errors_as_failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl ClassifyResponse for GrpcErrorsAsFailures {

fn classify_error<E>(self, error: &E) -> Self::FailureClass
where
E: fmt::Display + 'static,
E: fmt::Display,
{
GrpcFailureClass::Error(error.to_string())
}
Expand Down Expand Up @@ -238,7 +238,7 @@ impl ClassifyEos for GrpcEosErrorsAsFailures {

fn classify_error<E>(self, error: &E) -> Self::FailureClass
where
E: fmt::Display + 'static,
E: fmt::Display,
{
GrpcFailureClass::Error(error.to_string())
}
Expand Down
4 changes: 2 additions & 2 deletions tower-async-http/src/classify/map_failure_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where

fn classify_error<E>(self, error: &E) -> Self::FailureClass
where
E: std::fmt::Display + 'static,
E: std::fmt::Display,
{
(self.f)(self.inner.classify_error(error))
}
Expand All @@ -73,7 +73,7 @@ where

fn classify_error<E>(self, error: &E) -> Self::FailureClass
where
E: std::fmt::Display + 'static,
E: std::fmt::Display,
{
(self.f)(self.inner.classify_error(error))
}
Expand Down
14 changes: 7 additions & 7 deletions tower-async-http/src/classify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub trait MakeClassifier {
///
/// fn classify_error<E>(self, error: &E) -> Self::FailureClass
/// where
/// E: fmt::Display + 'static,
/// E: fmt::Display,
/// {
/// error.to_string()
/// }
Expand Down Expand Up @@ -180,7 +180,7 @@ pub trait ClassifyResponse {
/// errors. A retry policy might allow retrying some errors and not others.
fn classify_error<E>(self, error: &E) -> Self::FailureClass
where
E: fmt::Display + 'static;
E: fmt::Display;

/// Transform the failure classification using a function.
///
Expand Down Expand Up @@ -251,7 +251,7 @@ pub trait ClassifyEos {
/// errors. A retry policy might allow retrying some errors and not others.
fn classify_error<E>(self, error: &E) -> Self::FailureClass
where
E: fmt::Display + 'static;
E: fmt::Display;

/// Transform the failure classification using a function.
///
Expand Down Expand Up @@ -293,7 +293,7 @@ impl<T> ClassifyEos for NeverClassifyEos<T> {

fn classify_error<E>(self, _error: &E) -> Self::FailureClass
where
E: fmt::Display + 'static,
E: fmt::Display,
{
// `NeverClassifyEos` contains an `Infallible` so it can never be constructed
unreachable!()
Expand Down Expand Up @@ -346,7 +346,7 @@ impl ClassifyResponse for ServerErrorsAsFailures {

fn classify_error<E>(self, error: &E) -> Self::FailureClass
where
E: fmt::Display + 'static,
E: fmt::Display,
{
ServerErrorsFailureClass::Error(error.to_string())
}
Expand Down Expand Up @@ -391,11 +391,11 @@ mod usable_for_retries {
impl<ReqB, ResB, E, C> Policy<Request<ReqB>, Response<ResB>, E> for RetryBasedOnClassification<C>
where
C: ClassifyResponse + Clone,
E: fmt::Display + 'static,
E: fmt::Display,
C::FailureClass: IsRetryable,
ResB: http_body::Body,
Request<ReqB>: Clone,
E: std::error::Error + 'static,
E: std::error::Error,
{
async fn retry(
&self,
Expand Down
2 changes: 1 addition & 1 deletion tower-async-http/src/classify/status_in_range_is_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl ClassifyResponse for StatusInRangeAsFailures {

fn classify_error<E>(self, error: &E) -> Self::FailureClass
where
E: std::fmt::Display + 'static,
E: std::fmt::Display,
{
StatusInRangeFailureClass::Error(error.to_string())
}
Expand Down
2 changes: 1 addition & 1 deletion tower-async-http/src/trace/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<B, C, OnBodyChunkT, OnEosT, OnFailureT> Body
for ResponseBody<B, C, OnBodyChunkT, OnEosT, OnFailureT>
where
B: Body,
B::Error: fmt::Display + 'static,
B::Error: fmt::Display,
C: ClassifyEos,
OnEosT: OnEos,
OnBodyChunkT: OnBodyChunk<B::Data>,
Expand Down
2 changes: 1 addition & 1 deletion tower-async-http/src/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
//!
//! fn classify_error<E>(self, error: &E) -> Self::FailureClass
//! where
//! E: std::fmt::Display + 'static,
//! E: std::fmt::Display,
//! {
//! "something went wrong..."
//! }
Expand Down
2 changes: 1 addition & 1 deletion tower-async-http/src/trace/on_eos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl OnEos for () {

impl<F> OnEos for F
where
F: FnOnce(Option<&HeaderMap>, Duration, &Span),
F: Fn(Option<&HeaderMap>, Duration, &Span),
{
fn on_eos(self, trailers: Option<&HeaderMap>, stream_duration: Duration, span: &Span) {
self(trailers, stream_duration, span)
Expand Down
2 changes: 1 addition & 1 deletion tower-async-http/src/trace/on_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<B> OnResponse<B> for () {

impl<B, F> OnResponse<B> for F
where
F: FnOnce(&Response<B>, Duration, &Span),
F: Fn(&Response<B>, Duration, &Span),
{
fn on_response(self, response: &Response<B>, latency: Duration, span: &Span) {
self(response, latency, span)
Expand Down
4 changes: 2 additions & 2 deletions tower-async-http/src/trace/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ where
S: Service<Request<ReqBody>, Response = Response<ResBody>>,
ReqBody: Body,
ResBody: Body,
ResBody::Error: fmt::Display + 'static,
S::Error: fmt::Display + 'static,
ResBody::Error: fmt::Display,
S::Error: fmt::Display,
M: MakeClassifier,
M::Classifier: Clone,
MakeSpanT: MakeSpan<ReqBody>,
Expand Down
2 changes: 1 addition & 1 deletion tower-async-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
/// impl<T, Request> Service<Request> for Timeout<T>
/// where
/// T: Service<Request>,
/// T::Error: Into<Box<dyn Error + Send + Sync>> + 'static,
/// T::Error: Into<Box<dyn Error + Send + Sync>>,
/// T::Response: 'static,
/// {
/// // `Timeout` doesn't modify the response type, so we use `T`'s response type
Expand Down

0 comments on commit 8775674

Please sign in to comment.