Improve ergonomics when passing Clients as function arguments
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
## Feature Request
### Motivation
At the moment, any function that takes a Client as a parameter requires specifying some pretty scary-looking type bounds:
```rust
async fn foo(mut client: MyClient)
where
T: tonic::client::GrpcService,
T::ResponseBody: tonic::codegen::Body + tonic::codegen::HttpBody + Send + 'static,
T::Error: Into,
::Error: Into + Send,
::Data: Into + Send,
{ ... }
```
It would be nice to somehow simplify these sorts of declarations.
### Proposal
I'm not entirely sure how to work around this issue!
A heavyweight solution might be to write a proc macro that automagically includes these type bounds on a function. e.g:
```rust
#[tonic::clientbounds(T)]
async fn foo(mut client: MyClient) { ... }
```
### Alternatives
There are probably other, simpler solutions, but I can't think of any great ones off the top of my head. That said, I don't have a thorough understanding of tonic internals, so maybe there is an easy fix.
Contributor guide
Assessment
This issue has not been assessed yet.