Using Service
with axum 0.7
#2364
-
SummaryHi, impl<S> Service<Request<Body>> for TraceIdService<S>
where
S: Service<Request<Body>>,
{
type Response = S::Response;
type Error = S::Error;
type Future = Instrumented<S::Future>;
fn call(&self, mut req: Request<Body>) -> Self::Future {
let trace_id = TraceId::generate();
let span = trace_span!("request", trace_id = trace_id.to_string());
req.extensions_mut().insert(trace_id);
self.inner.call(req).instrument(span)
}
} And fails with the following error :
I tried switching dependencies around a bunch but I am having trouble resolving this. How can I solve this ? The whole code is here on github. axum version0.7.1 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That is because you need to implement impl<S> tower::Service<Request<Body>> for TraceIdService<S>
where
S: tower::Service<Request<Body>>,
{
type Response = S::Response;
type Error = S::Error;
type Future = Instrumented<S::Future>;
fn poll_ready(&mut self, cx: &mut std::task::Context<'_>) -> std::task::Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx)
}
fn call(&mut self, mut req: Request<Body>) -> Self::Future {
let trace_id = TraceId::generate();
let span = trace_span!("request", trace_id = trace_id.to_string());
req.extensions_mut().insert(trace_id);
self.inner.call(req).instrument(span)
}
} While the traits have the same name they're not interchangeable. |
Beta Was this translation helpful? Give feedback.
That is because you need to implement
tower::Service
and nothyper::Service
: