Add tower-h2 and more macro

This commit is contained in:
Lucio Franco
2019-08-11 13:48:13 -04:00
parent aef683fe35
commit 404f7d8931
16 changed files with 727 additions and 33 deletions
+1 -1
View File
@@ -8,7 +8,6 @@ edition = "2018"
proc-macro = true
[dependencies]
tonic = { path = "../tonic" }
syn = { version = "0.15", features = ["full"] }
quote = "0.6"
proc-macro2 = "0.4"
@@ -17,3 +16,4 @@ tower-service = { git = "https://github.com/tower-rs/tower", branch = "std-futur
[dev-dependencies]
tokio = "=0.2.0-alpha.1"
tonic = { path = "../tonic" }
+1 -29
View File
@@ -7,7 +7,7 @@ use quote::quote;
use syn::{ImplItem, ImplItemMethod, ItemImpl, Type};
#[proc_macro_attribute]
pub fn grpc(attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn server(attr: TokenStream, item: TokenStream) -> TokenStream {
let service = load_service(attr);
let mut original = item.clone();
let ItemImpl { self_ty, items, .. } = syn::parse_macro_input!(item as ItemImpl);
@@ -36,33 +36,6 @@ pub fn grpc(attr: TokenStream, item: TokenStream) -> TokenStream {
}
}
// let ts = quote! {
// impl<'a> tower_service::Service<tonic::Request<()>> for #s {
// type Response = tonic::Response<()>;
// type Error = tonic::Status;
// type Future = tonic::ResponseFuture<'a, Self::Response, Self::Error>;
// fn poll_ready(&mut self, _cx: &mut std::task::Context<'_>) -> std::task::Poll<Result<(), Self::Error>> {
// std::task::Poll::Ready(Ok(()))
// }
// fn call(&mut self, request: tonic::Request<()>) -> Self::Future {
// Box::pin(self.#m_ident(request))
// }
// }
// };
// let ts = quote! {
// impl tonic::GrpcInnerService<tonic::Request<()>> for #s {
// type Response = tonic::Response<()>;
// fn call<'a>(&'a mut self, request: tonic::Request<()>) -> tonic::ResponseFuture<'a, Self::Response>
// where Self: 'a {
// Box::pin(self.#m_ident(request))
// }
// }
// };
let ts = quote! {
pub struct GrpcServer {
inner: std::sync::Arc<#s>,
@@ -88,7 +61,6 @@ pub fn grpc(attr: TokenStream, item: TokenStream) -> TokenStream {
Box::pin(async move {
inner.#m_ident(request).await
})
//self.#m_ident(request)
}
}
};
@@ -3,7 +3,6 @@
use std::time::Duration;
use tokio::timer::Delay;
use tonic::{Request, Response, Status};
use tonic_macros::grpc;
// #[derive(Debug)]
// struct HelloRequest;
@@ -15,7 +14,7 @@ struct MyGreeter {
data: String,
}
#[grpc(service = "proto/helloworld.proto")]
#[tonic::server(service = "proto/helloworld.proto")]
impl MyGreeter {
pub async fn say_hello(&self, request: Request<()>) -> Result<Response<()>, Status> {
println!("Got a request: {:?}", request);