-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would still make sense for this to a const SERVICE_NAME: &str
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point, should the trait const below be const NAME: &'static str = SERVICE_NAME;
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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::NAME
whenT
has multiple generics:This is particularly egregious when using the
HealthReporter
methods sinceHealthReporter::set_serving
requires a fully qualifiedServiceServer<T>
:Solution
expose a
pub const fn service_name() -> &'static str
that returns the formatted string.