Dynamically named services
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
## 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.
Contributor guide
Assessment
This issue has not been assessed yet.