Skip to content

Commit

Permalink
fix(build): Allow non_camel_case_types on codegen structs
Browse files Browse the repository at this point in the history
This commit adjusts the code generation for the internal structs in the
implementation of Service<http::Request<HyperBody>> for *Server<T> in
order to annotate internal structs whose names are derived from gRPC
method names with `[allow(non_camel_case_types)]`. This supresses
compiler warnings about type names when compiling generated code. The
struct names are not exposed externally, so this has no impact on types
seen by library consumers.

Fixes #295.
  • Loading branch information
jen20 authored Mar 19, 2020
1 parent 61e0429 commit 224280d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ fn generate_unary<'a, T: Method<'a>>(
let (request, response) = method.request_response_name(context);

quote! {
#[allow(non_camel_case_types)]
struct #service_ident<T: #server_trait >(pub Arc<T>);

impl<T: #server_trait> tonic::server::UnaryService<#request> for #service_ident<T> {
Expand Down Expand Up @@ -310,6 +311,7 @@ fn generate_server_streaming<'a, T: Method<'a>>(
let response_stream = quote::format_ident!("{}Stream", method.identifier());

quote! {
#[allow(non_camel_case_types)]
struct #service_ident<T: #server_trait >(pub Arc<T>);

impl<T: #server_trait> tonic::server::ServerStreamingService<#request> for #service_ident<T> {
Expand Down Expand Up @@ -360,6 +362,7 @@ fn generate_client_streaming<'a, T: Method<'a>>(
let codec_name = syn::parse_str::<syn::Path>(context.codec_name()).unwrap();

quote! {
#[allow(non_camel_case_types)]
struct #service_ident<T: #server_trait >(pub Arc<T>);

impl<T: #server_trait> tonic::server::ClientStreamingService<#request> for #service_ident<T>
Expand Down Expand Up @@ -413,6 +416,7 @@ fn generate_streaming<'a, T: Method<'a>>(
let response_stream = quote::format_ident!("{}Stream", method.identifier());

quote! {
#[allow(non_camel_case_types)]
struct #service_ident<T: #server_trait>(pub Arc<T>);

impl<T: #server_trait> tonic::server::StreamingService<#request> for #service_ident<T>
Expand Down

0 comments on commit 224280d

Please sign in to comment.