Compile error "...unsatisfied trait bounds" when (from what I can see) the struct should implement the trait

It's better shown than described: https://www.rustexplorer.com/b/g3wdgs

In short, why doesn't AsyncFilter implement Service<_> in this scenario?

you are missing certain bounds for the inner S:

impl<S> Service<Request<Body>> for MyService<S>
where
	S: Service<Request<Body>, Response = Response<Body>> + Clone,
	S::Error: Into<BoxError>, {
//...
}

but you will get another error at this line:

 self.service=Some(service);

because after previous lines, service is not S, but some complicated AndThen<AsyncFilter<...>> opaque type. you'll have to use trait object if you want to store the chained wrapper type.

DUhhhh - thank you SO much - yeah i realized I was gonna get the second error, but I've slightly refactored to handle that (I don't store the valus at all now)

Ok, I have changed the code around - and the traits now get implemented... but (again due to impossibly long types) I can't store the inner future. Now, I know my "Future" Assoc Type on line 112 is wrong ... except that it IS a

Future<Output = Result<Response<Body>, BoxError>>>

that I need.

Again, any help you could give would be gratefully accepted.

as already suggested, just use a trait object:

type Future = Pin<Box<dyn Future<Output = Result<S::Response, BoxError>>>>;

then you also need to change the associated Error type to match the Future:

type Error = BoxError;

and in your service, return the Future type as you defined (i.e. Pin<Box<dyn Future<...>>>):

fn call(&mut self, req: Request<Body>) -> Self::Future {
	let mut service = self.inner.take().unwrap();
	let mut service = service.filter_async(pre_integration_chain_filter);
	let mut service = service.and_then(post_integration_chain_filter);
	Box::pin(service.call(req))
}

then you just fix the lifetime bound as suggested by the compiler:

where
	S: Service<Request<Body>, Response = Response<Body>> + Clone + 'static,

disclaimer:

I don't understand what you are trying to do, I just fixed the type error reported by the compiler.

async is not the most intuitive concept in rust, and combining async with complicated types is not easy to handle. if you are new to rust async. I suggest you first get yourself comfortable with the basics. for example, typically client side code is simpler then server side.

you might want to read the rust async book if not already done.

Hey there - thx a million for this. I am, actually, fairly familiar with async, but, evidently not quite as much with with its use in Tower as I thought. It was all the nested types that Tower introduces that put my brain in a loop! As you say, these values are probably not meant for storing but for using immediately!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.