grpc / grpc/grpc-rust

Client trait to allow for generic wrappers

Open
#1,490 4 comments 10 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
12.5k
Forks
1.3k
Avg merge
4d 7h
Merged PRs (30d)
24

Description

This is related to #671 though I didn't want to bump the old issue.
It would be really helpful if there were a common trait implemented by all tonic clients that contained functions like `with_interceptor`, `with_origin`, etc.

I think previous issues on this topic were for the purposes of mocking which is appropriately handled by the example in the repo, but this doesn't solve the issue of wanting to write generic client wrappers.

For example, I'd like to create a wrapper that adds a mandatory interceptor for all outgoing requests, regardless of which service it's to.

Something like
```
struct RpcWrapper {
client: T
}
impl RpcWrapper {
fn new(channel: Channel) -> Self {
RpcWrapper {
client: T::with_interceptor(channel, MyInterceptor)
}
}
}
```
and then with an appropriate `Deref` impl, this wrapper should otherwise act exactly like the concrete client type.

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.