feat(build): support adding attributes to clients and servers (#684)

This commit is contained in:
Conner Bryan
2021-07-08 15:01:28 -04:00
committed by GitHub
parent 89df3380dd
commit a948a8f884
6 changed files with 216 additions and 12 deletions
+6 -1
View File
@@ -1,4 +1,4 @@
use super::{Method, Service};
use super::{Attributes, Method, Service};
use crate::{generate_doc_comment, generate_doc_comments, naive_snake_case};
use proc_macro2::{Span, TokenStream};
use quote::quote;
@@ -13,6 +13,7 @@ pub fn generate<T: Service>(
emit_package: bool,
proto_path: &str,
compile_well_known_types: bool,
attributes: &Attributes,
) -> TokenStream {
let methods = generate_methods(service, proto_path, compile_well_known_types);
@@ -35,6 +36,8 @@ pub fn generate<T: Service>(
service.identifier()
);
let transport = generate_transport(&server_service, &server_trait, &path);
let mod_attributes = attributes.for_mod(package);
let struct_attributes = attributes.for_struct(&path);
let compression_enabled = cfg!(feature = "compression");
@@ -64,6 +67,7 @@ pub fn generate<T: Service>(
quote! {
/// Generated server implementations.
#(#mod_attributes)*
pub mod #server_mod {
#![allow(unused_variables, dead_code, missing_docs)]
use tonic::codegen::*;
@@ -71,6 +75,7 @@ pub fn generate<T: Service>(
#generated_trait
#service_doc
#(#struct_attributes)*
#[derive(Debug)]
pub struct #server_service<T: #server_trait> {
inner: _Inner<T>,