stepancheg / grpc-rust

Rust implementation of gRPC
MIT License
1.37k stars 124 forks source link

Generated client code should be `Arc<T>`. #98

Closed thedodd closed 5 years ago

thedodd commented 6 years ago

The client code is generated such that the implementation of the service is made directly on the struct, as opposed to a wrapping Arc<T>. Without Arc<T>, an instance of the client can not be easily shared.

If the generated code were to take the approach of:

pub struct ServiceClientInner {
    pub grpc_client: ::grpc::Client,
    ... // Whatever other fields.
}

pub type ServiceClient = Arc<ServiceClientInner>;

impl Service for ServiceClient {
    ... // Implementation code here.
}

Taking this approach will allow for the service to be immutably shared throughout a multi-threaded program with very little overhead. Due to privacy issues with the current code generated struct, this abstraction can not be implemented in a containing module.

If this ticket needs to be duplicated in the code generation repo, just let me know. Happy to open it there as well.

thedodd commented 6 years ago

I've been wanting to jump in and start getting some work done on this repo, so I'm gonna go ahead and use this as an opportunity to get started. I definitely need this for one of the services I have right now. Will get started.

thedodd commented 6 years ago

I believe the sentiment in this issue is similar: https://github.com/stepancheg/grpc-rust/issues/101

stepancheg commented 5 years ago

Fixed now.

thedodd commented 5 years ago

👍