Add client, client codegen, helloworld and routeguide client examples

This commit is contained in:
Lucio Franco
2019-08-17 23:31:32 -04:00
parent 3951bcf7fe
commit 2ebad2d778
26 changed files with 883 additions and 364 deletions
+32
View File
@@ -3,12 +3,44 @@
extern crate proc_macro;
mod client;
mod service;
use proc_macro::TokenStream;
use quote::quote;
use serde::Deserialize;
use syn::{AttributeArgs, ItemImpl};
#[proc_macro]
pub fn client(attr: TokenStream) -> TokenStream {
let args = syn::parse_macro_input!(attr as AttributeArgs);
let (service, proto_path) = load_service(args);
let service_ident = quote::format_ident!("{}Client", service.name);
let methods = client::generate(service, proto_path);
let output = quote! {
pub struct #service_ident <T> {
inner: tonic::client::Grpc<T>,
}
impl<T> #service_ident <T>
where T: tonic::GrpcService<tonic::body::BoxAsyncBody>,
T::ResponseBody: tonic::body::Body + tonic::_codegen::HttpBody + Send + 'static,
<T::ResponseBody as tonic::_codegen::HttpBody>::Error: Into<tonic::error::Error> + Send,
<T::ResponseBody as tonic::_codegen::HttpBody>::Data: Send, {
pub fn new(inner: T) -> Self {
let inner = tonic::client::Grpc::new(inner);
Self { inner }
}
#methods
}
};
TokenStream::from(output)
}
#[proc_macro_attribute]
pub fn server(attr: TokenStream, item: TokenStream) -> TokenStream {
let mut original = item.clone();