I need some help with Rust compiler “fun” in threa...
# development
f
I need some help with Rust compiler “fun” in thread.
errors are:
Copy code
error[E0207]: the type parameter `ReqBody` is not constrained by the impl trait, self type, or predicates
  --> grpc_util/src/metrics.rs:74:6
   |
74 | impl<ReqBody, S> Future for NetworkMetricsFuture<S::Future>
   |      ^^^^^^^ unconstrained type parameter

error[E0207]: the type parameter `S` is not constrained by the impl trait, self type, or predicates
  --> grpc_util/src/metrics.rs:74:15
   |
74 | impl<ReqBody, S> Future for NetworkMetricsFuture<S::Future>
   |               ^ unconstrained type parameter
code in question is:
Copy code
impl<ReqBody, S> Future for NetworkMetricsFuture<S::Future>
where
  S: Service<Request<ReqBody>>,
{
  type Output = S::Future;
  ...
}
which should be the same as this code which is already on `main`:
Copy code
impl<ReqBody, S> Service<Request<ReqBody>> for SetRequestHeaders<S>
where
  S: Service<Request<ReqBody>>,
{
  type Response = S::Response;
  type Error = S::Error;
  type Future = S::Future;
  ...
}
I copied an existing pattern and now the copy has “unconstrained type parameter”
not immediately obvious to me what the difference between the two usages is
w
rather than defining your own future, you could probably return BoxFuture, and then use combinators in the
call
body?
also, consider using
layer_fn
rather than defining a layer: https://docs.rs/tower/latest/tower/layer/fn.layer_fn.html
(once that’s working, can revisit not boxing)
f
rather than defining your own future, you could probably return BoxFuture, and then use combinators in the
call
body?
good idea, will try that next. I was trying to go with the more efficient solution first.
w
with regard to existing patterns, it seems like copying a “wrap a service” example which defines its own future from somewhere in
tower
would be the best source
f
and I found
PropagateRequestIdResponseFuture
they don’t try to constrain S but rather the inner future: ``````
impl<F, B, E> Future for PropagateRequestIdResponseFuture<F> where F: Future<Output = Result<Response<B>, E>>, {
Copy code
type Output = Result<Response<B>, E>;
w
yea.
f
constraining the Future works
and thanks for the help!
w
sure thing!