Expose formatted service name as a const fn#1684
Conversation
|
+1 to this! It would make it a lot less verbose to get the service name. |
tonic-build/src/server.rs
Outdated
|
|
||
| quote! { | ||
| #name_doc | ||
| pub const fn service_name() -> &'static str { |
There was a problem hiding this comment.
I think it would still make sense for this to a const SERVICE_NAME: &str?
There was a problem hiding this comment.
fair point, should the trait const below be const NAME: &'static str = SERVICE_NAME; then?
There was a problem hiding this comment.
Might be nice, want to make that change?
|
I cannot seem to reproduce this diff locally with protobuf 25: |
|
@mkatychev you just need to run |
Hi @LucioFranco I did that with the given version of protoc (25.1) on macOS and I am not able to produce the comment diff in the run log |
Run |
|
Thanks! |
Motivation
It is oftentimes cumbersome to use
tonic::server::NamedService::NAMEwhenThas multiple generics:This is particularly egregious when using the
HealthReportermethods sinceHealthReporter::set_servingrequires a fully qualifiedServiceServer<T>:Solution
expose a
pub const fn service_name() -> &'static strthat returns the formatted string.