Include proto macros (#13)

This commit is contained in:
John Doneth
2019-09-30 14:05:37 -04:00
committed by Lucio Franco
parent 49872ce904
commit 3edaa424d9
13 changed files with 32 additions and 14 deletions
+2 -2
View File
@@ -54,7 +54,7 @@ $ cargo +beta build
```rust ```rust
pub mod hello_world { pub mod hello_world {
include!(concat!(env!("OUT_DIR"), "/helloworld.rs")); tonic::include_proto!("helloworld");
} }
use hello_world::{client::GreeterClient, HelloRequest}; use hello_world::{client::GreeterClient, HelloRequest};
@@ -81,7 +81,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
use tonic::{transport::Server, Request, Response, Status}; use tonic::{transport::Server, Request, Response, Status};
pub mod hello_world { pub mod hello_world {
include!(concat!(env!("OUT_DIR"), "/helloworld.rs")); tonic::include_proto!("helloworld");
} }
use hello_world::{ use hello_world::{
+1 -1
View File
@@ -1,5 +1,5 @@
pub mod pb { pub mod pb {
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs")); tonic::include_proto!("grpc.examples.echo");
} }
use http::header::HeaderValue; use http::header::HeaderValue;
+1 -1
View File
@@ -1,5 +1,5 @@
pub mod pb { pub mod pb {
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs")); tonic::include_proto!("grpc.examples.echo");
} }
use pb::{EchoRequest, EchoResponse}; use pb::{EchoRequest, EchoResponse};
+1 -1
View File
@@ -1,5 +1,5 @@
pub mod hello_world { pub mod hello_world {
include!(concat!(env!("OUT_DIR"), "/helloworld.rs")); tonic::include_proto!("helloworld");
} }
use hello_world::{client::GreeterClient, HelloRequest}; use hello_world::{client::GreeterClient, HelloRequest};
+1 -1
View File
@@ -1,7 +1,7 @@
use tonic::{transport::Server, Request, Response, Status}; use tonic::{transport::Server, Request, Response, Status};
pub mod hello_world { pub mod hello_world {
include!(concat!(env!("OUT_DIR"), "/helloworld.rs")); tonic::include_proto!("helloworld");
} }
use hello_world::{ use hello_world::{
+2 -2
View File
@@ -1,5 +1,5 @@
pub mod pb { pub mod pb {
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs")); tonic::include_proto!("grpc.examples.echo");
} }
use pb::{client::EchoClient, EchoRequest}; use pb::{client::EchoClient, EchoRequest};
@@ -15,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = EchoClient::new(channel); let mut client = EchoClient::new(channel);
for _ in 0..12 { for _ in 0..12usize {
let request = tonic::Request::new(EchoRequest { let request = tonic::Request::new(EchoRequest {
message: "hello".into(), message: "hello".into(),
}); });
+1 -1
View File
@@ -1,5 +1,5 @@
pub mod pb { pub mod pb {
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs")); tonic::include_proto!("grpc.examples.echo");
} }
use pb::{EchoRequest, EchoResponse}; use pb::{EchoRequest, EchoResponse};
+2 -2
View File
@@ -4,8 +4,8 @@ use std::time::{Duration, Instant};
use tokio::timer::Interval; use tokio::timer::Interval;
use tonic::Request; use tonic::Request;
mod route_guide { pub mod route_guide {
include!(concat!(env!("OUT_DIR"), "/routeguide.rs")); tonic::include_proto!("routeguide");
} }
use route_guide::client::RouteGuideClient; use route_guide::client::RouteGuideClient;
+1 -1
View File
@@ -11,7 +11,7 @@ use tonic::transport::Server;
use tonic::{Request, Response, Status}; use tonic::{Request, Response, Status};
pub mod routeguide { pub mod routeguide {
include!(concat!(env!("OUT_DIR"), "/routeguide.rs")); tonic::include_proto!("routeguide");
} }
use routeguide::{server, Feature, Point, Rectangle, RouteNote, RouteSummary}; use routeguide::{server, Feature, Point, Rectangle, RouteNote, RouteSummary};
+1 -1
View File
@@ -1,5 +1,5 @@
pub mod pb { pub mod pb {
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs")); tonic::include_proto!("/grpc.examples.echo");
} }
use pb::{client::EchoClient, EchoRequest}; use pb::{client::EchoClient, EchoRequest};
+1 -1
View File
@@ -1,5 +1,5 @@
pub mod pb { pub mod pb {
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs")); tonic::include_proto!("/grpc.examples.echo");
} }
use pb::{EchoRequest, EchoResponse}; use pb::{EchoRequest, EchoResponse};
+1
View File
@@ -77,6 +77,7 @@ pub mod server;
#[cfg(feature = "transport")] #[cfg(feature = "transport")]
pub mod transport; pub mod transport;
mod macros;
mod request; mod request;
mod response; mod response;
mod status; mod status;
+17
View File
@@ -0,0 +1,17 @@
/// Include generated proto server and client items.
///
/// # Example
/// ```rust,no_run
/// pub mod hello_world {
/// tonic::include_proto!("helloworld");
/// }
/// ```
#[macro_export]
macro_rules! include_proto {
($package: tt) => {
include!(concat!(
env!("OUT_DIR"),
concat!("/", $package, ".rs")
));
};
}