Skip to content
6 changes: 6 additions & 0 deletions tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,14 @@ fn generate_named(
service_name: &str,
) -> TokenStream {
let service_name = syn::LitStr::new(service_name, proc_macro2::Span::call_site());
let name_doc = generate_doc_comment(" Generated gRPC service name");

quote! {
#name_doc
pub const fn service_name() -> &'static str {
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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?

#service_name
}

impl<T: #server_trait> tonic::server::NamedService for #server_service<T> {
const NAME: &'static str = #service_name;
}
Expand Down