grpc / grpc/grpc-rust

Improve ergonomics when passing Clients as function arguments

Open
#110 10 comments 17 reactions 0 assignees View on GitHub
A-tonic C-enhancement E-help-wanted T-docs
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.