Include proto macros (#13)
This commit is contained in:
committed by
Lucio Franco
parent
49872ce904
commit
3edaa424d9
@@ -54,7 +54,7 @@ $ cargo +beta build
|
||||
|
||||
```rust
|
||||
pub mod hello_world {
|
||||
include!(concat!(env!("OUT_DIR"), "/helloworld.rs"));
|
||||
tonic::include_proto!("helloworld");
|
||||
}
|
||||
|
||||
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};
|
||||
|
||||
pub mod hello_world {
|
||||
include!(concat!(env!("OUT_DIR"), "/helloworld.rs"));
|
||||
tonic::include_proto!("helloworld");
|
||||
}
|
||||
|
||||
use hello_world::{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod pb {
|
||||
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs"));
|
||||
tonic::include_proto!("grpc.examples.echo");
|
||||
}
|
||||
|
||||
use http::header::HeaderValue;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod pb {
|
||||
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs"));
|
||||
tonic::include_proto!("grpc.examples.echo");
|
||||
}
|
||||
|
||||
use pb::{EchoRequest, EchoResponse};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod hello_world {
|
||||
include!(concat!(env!("OUT_DIR"), "/helloworld.rs"));
|
||||
tonic::include_proto!("helloworld");
|
||||
}
|
||||
|
||||
use hello_world::{client::GreeterClient, HelloRequest};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use tonic::{transport::Server, Request, Response, Status};
|
||||
|
||||
pub mod hello_world {
|
||||
include!(concat!(env!("OUT_DIR"), "/helloworld.rs"));
|
||||
tonic::include_proto!("helloworld");
|
||||
}
|
||||
|
||||
use hello_world::{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod pb {
|
||||
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs"));
|
||||
tonic::include_proto!("grpc.examples.echo");
|
||||
}
|
||||
|
||||
use pb::{client::EchoClient, EchoRequest};
|
||||
@@ -15,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let mut client = EchoClient::new(channel);
|
||||
|
||||
for _ in 0..12 {
|
||||
for _ in 0..12usize {
|
||||
let request = tonic::Request::new(EchoRequest {
|
||||
message: "hello".into(),
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod pb {
|
||||
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs"));
|
||||
tonic::include_proto!("grpc.examples.echo");
|
||||
}
|
||||
|
||||
use pb::{EchoRequest, EchoResponse};
|
||||
|
||||
@@ -4,8 +4,8 @@ use std::time::{Duration, Instant};
|
||||
use tokio::timer::Interval;
|
||||
use tonic::Request;
|
||||
|
||||
mod route_guide {
|
||||
include!(concat!(env!("OUT_DIR"), "/routeguide.rs"));
|
||||
pub mod route_guide {
|
||||
tonic::include_proto!("routeguide");
|
||||
}
|
||||
|
||||
use route_guide::client::RouteGuideClient;
|
||||
|
||||
@@ -11,7 +11,7 @@ use tonic::transport::Server;
|
||||
use tonic::{Request, Response, Status};
|
||||
|
||||
pub mod routeguide {
|
||||
include!(concat!(env!("OUT_DIR"), "/routeguide.rs"));
|
||||
tonic::include_proto!("routeguide");
|
||||
}
|
||||
|
||||
use routeguide::{server, Feature, Point, Rectangle, RouteNote, RouteSummary};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod pb {
|
||||
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs"));
|
||||
tonic::include_proto!("/grpc.examples.echo");
|
||||
}
|
||||
|
||||
use pb::{client::EchoClient, EchoRequest};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod pb {
|
||||
include!(concat!(env!("OUT_DIR"), "/grpc.examples.echo.rs"));
|
||||
tonic::include_proto!("/grpc.examples.echo");
|
||||
}
|
||||
|
||||
use pb::{EchoRequest, EchoResponse};
|
||||
|
||||
@@ -77,6 +77,7 @@ pub mod server;
|
||||
#[cfg(feature = "transport")]
|
||||
pub mod transport;
|
||||
|
||||
mod macros;
|
||||
mod request;
|
||||
mod response;
|
||||
mod status;
|
||||
|
||||
@@ -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")
|
||||
));
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user