diff --git a/examples/helloworld-tutorial.md b/examples/helloworld-tutorial.md index ae435b5..608768b 100644 --- a/examples/helloworld-tutorial.md +++ b/examples/helloworld-tutorial.md @@ -129,7 +129,7 @@ At the root of your crate, create a `build.rs` file and add the following code: ```rust fn main() -> Result<(), Box> { - tonic_build::prost::compile_protos("proto/helloworld.proto")?; + tonic_build::compile_protos("proto/helloworld.proto")?; Ok(()) } ``` diff --git a/examples/routeguide-tutorial.md b/examples/routeguide-tutorial.md index 21d4ed5..a4a9fe1 100644 --- a/examples/routeguide-tutorial.md +++ b/examples/routeguide-tutorial.md @@ -199,7 +199,7 @@ Create a `build.rs` file at the root of your crate: ```rust fn main() { - tonic_build::prost::compile_protos("proto/route_guide.proto") + tonic_build::compile_protos("proto/route_guide.proto") .unwrap_or_else(|e| panic!("Failed to compile protos {:?}", e)); } ``` diff --git a/examples/src/helloworld/server_blocking.rs b/examples/src/helloworld/server_blocking.rs new file mode 100644 index 0000000..fbaaf9e --- /dev/null +++ b/examples/src/helloworld/server_blocking.rs @@ -0,0 +1,40 @@ +use tonic::{transport::Server, Request, Response, Status}; + +use hello_world::greeter_server::{Greeter, GreeterServer}; +use hello_world::{HelloReply, HelloRequest}; + +use tokio::runtime::Runtime; + +pub mod hello_world { + tonic::include_proto!("helloworld"); +} + +#[derive(Debug, Default)] +pub struct MyGreeter {} + +#[tonic::async_trait] +impl Greeter for MyGreeter { + async fn say_hello( + &self, + request: Request, + ) -> Result, Status> { + println!("Got a request: {:?}", request); + + let reply = hello_world::HelloReply { + message: format!("Hello {}!", request.into_inner().name).into(), + }; + + Ok(Response::new(reply)) + } +} + +fn main() { + let addr = "[::1]:50051".parse().unwrap(); + let greeter = MyGreeter::default(); + + let mut rt = Runtime::new().expect("failed to obtain a new RunTime object"); + let server_future = Server::builder() + .add_service(GreeterServer::new(greeter)) + .serve(addr); + rt.block_on(server_future).expect("failed to successfully run the future on RunTime"); +}