hyperium / tonic

A native gRPC client & server implementation with async/await support.
https://docs.rs/tonic
MIT License
9.35k stars 957 forks source link

Dynamically named services #1667

Open lemma105 opened 3 months ago

lemma105 commented 3 months ago

Feature Request

Currently the NamedService trait assumes that codegen from Prost is used to generate at compile time a const field that has a service name. This trait must be implemented on a service in order for the router to accept it (add_service in router.rs requires the NamedService trait).

This prevents the creation of services with names not known at compile time.

Motivation

I am creating an IDL agnostic server, using FFI to bridge to C++ which will handle the payload as the server is unable to serialize or deserialize it. In this scheme, the C++ client code will register methods onto a service with callbacks. Since the server will not know at compile time what the services it will be running are called, I currently must use a single placeholder service name.

Proposal

pub trait NamedService {
    const NAME: &'static str;
}

Needs to shift to something more like:

pub trait NamedService {
    fn get_name(self) -> &str;
}

And the subsequent internal modifications to both Tonic and Prost to support this need implemented.

I am new to Rust and not confident enough to implement this publicly. Suggestions and feedback welcomed.