https://pantsbuild.org/ logo
#development
Title
# development
f

fast-nail-55400

06/28/2022, 8:22 PM
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

witty-crayon-22786

06/28/2022, 8:44 PM
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

fast-nail-55400

06/28/2022, 8:44 PM
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

witty-crayon-22786

06/28/2022, 8:46 PM
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

fast-nail-55400

06/28/2022, 8:48 PM
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

witty-crayon-22786

06/28/2022, 8:49 PM
yea.
f

fast-nail-55400

06/28/2022, 9:02 PM
constraining the Future works
and thanks for the help!
w

witty-crayon-22786

06/28/2022, 9:57 PM
sure thing!