Skip to content

Commit faa26ac

Browse files
alceLucioFranco
authored andcommitted
chore(example) Fix routeguide errors (#218)
* chore(example) Fix routeguide errors * remove redundant line
1 parent ec1f37e commit faa26ac

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

examples/routeguide-tutorial.md

+23-17
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ You should see some logging output flying past really quickly on both terminal w
6767
shell where you ran the client binary, you should see the output of the bidirectional streaming rpc,
6868
printing 1 line per second:
6969

70-
NOTE = RouteNote { location: Some(Point { latitude: 409146139, longitude: -746188906 }), message: "at 1.000319208s" }
70+
```
71+
NOTE = RouteNote { location: Some(Point { latitude: 409146139, longitude: -746188906 }), message: "at 1.000319208s" }
72+
```
7173

7274
If you scroll up you should see the output of the other 3 request types: simple rpc, server-side
7375
streaming and client-side streaming.
7476

7577

76-
[readme]: https://github.com/hyperium/tonic#getting-started
77-
7878
## Project setup
7979

8080
We will develop our example from scratch in a new crate:
@@ -259,7 +259,7 @@ pub mod routeguide {
259259
tonic::include_proto!("routeguide");
260260
}
261261

262-
use routeguide::route_guide_server::RouteGuide;
262+
use routeguide::route_guide_server::{RouteGuide, RouteGuideServer};
263263
use routeguide::{Feature, Point, Rectangle, RouteNote, RouteSummary};
264264
```
265265

@@ -269,16 +269,16 @@ the package declared in in our `.proto` file, not a filename, e.g "routeguide.rs
269269
With this in place, we can stub out our service implementation:
270270

271271
```rust
272-
use std::pin::Pin;
273-
274272
use futures_core::Stream;
273+
use std::pin::Pin;
274+
use std::sync::Arc;
275275
use tokio::sync::mpsc;
276276
use tonic::{Request, Response, Status};
277277
```
278278

279279
```rust
280280
#[tonic::async_trait]
281-
impl server::RouteGuide for RouteGuide {
281+
impl RouteGuide for RouteGuideService {
282282
async fn get_feature(&self, _request: Request<Point>) -> Result<Response<Feature>, Status> {
283283
unimplemented!()
284284
}
@@ -370,7 +370,7 @@ when performing feature lookups. You can find them in
370370

371371
[route-guide-db]: https://github.com/hyperium/tonic/blob/master/examples/data/route_guide_db.json
372372
[data-module]: https://github.com/hyperium/tonic/blob/master/examples/src/routeguide/data.rs
373-
[in-range-fn]: https://github.com/hyperium/tonic/blob/master/examples/src/routeguide/server.rs#L177
373+
[in-range-fn]: https://github.com/hyperium/tonic/blob/master/examples/src/routeguide/server.rs#L174
374374

375375
#### Request and Response types
376376
All our service methods receive a `tonic::Request<T>` and return a
@@ -449,7 +449,7 @@ async fn record_route(
449449
request: Request<tonic::Streaming<Point>>,
450450
) -> Result<Response<RouteSummary>, Status> {
451451
let stream = request.into_inner();
452-
futures::pin_mut!(stream);
452+
futures_util::pin_mut!(stream);
453453

454454
let mut summary = RouteSummary::default();
455455
let mut last_point = None;
@@ -488,7 +488,13 @@ Finally, let's look at our bidirectional streaming RPC `route_chat`, which recei
488488
of `RouteNote`s and returns a stream of `RouteNote`s.
489489

490490
```rust
491-
type RouteChatStream = Pin<Box<dyn Stream<Item = Result<RouteNote, Status>> + Send + 'static>>;
491+
use std::collections::HashMap;
492+
```
493+
494+
```rust
495+
type RouteChatStream =
496+
Pin<Box<dyn Stream<Item = Result<RouteNote, Status>> + Send + Sync + 'static>>;
497+
492498

493499
async fn route_chat(
494500
&self,
@@ -498,7 +504,7 @@ async fn route_chat(
498504
let stream = request.into_inner();
499505

500506
let output = async_stream::try_stream! {
501-
futures::pin_mut!(stream);
507+
futures_util::pin_mut!(stream);
502508

503509
while let Some(note) = stream.next().await {
504510
let note = note?;
@@ -547,7 +553,7 @@ use tonic::transport::Server;
547553
async fn main() -> Result<(), Box<dyn std::error::Error>> {
548554
let addr = "[::1]:10000".parse().unwrap();
549555

550-
let route_guide = RouteGuide {
556+
let route_guide = RouteGuideService {
551557
features: Arc::new(data::load()),
552558
};
553559

@@ -561,14 +567,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
561567

562568
To handle requests, `Tonic` uses [Tower] and [hyper] internally. What this means,
563569
among other things, is that we have a flexible and composable stack we can build on top of. We can,
564-
for example, add an [interceptor][authentication-example] or implement [routing][router-example].
565-
In the future, Tonic may include higher level support for routing and interceptors.
570+
for example, add an [interceptor][authentication-example] to process requests before they reach our service
571+
methods.
566572

567573

568574
[Tower]: https://github.com/tower-rs
569575
[hyper]: https://github.com/hyperium/hyper
570576
[authentication-example]: https://github.com/hyperium/tonic/blob/master/examples/src/authentication/server.rs#L56
571-
[router-example]: https://github.com/hyperium/tonic/blob/master/interop/src/bin/server.rs#L73
572577

573578
<a name="client"></a>
574579
## Creating the client
@@ -596,7 +601,8 @@ $ mv src/main.rs src/server.rs
596601
$ touch src/client.rs
597602
```
598603

599-
To call service methods, we first need to create a gRPC *client* to communicate with the server.
604+
To call service methods, we first need to create a gRPC *client* to communicate with the server. Like in the server
605+
case, we'll start by bringing the generated code into scope:
600606

601607
```rust
602608
pub mod routeguide {
@@ -755,7 +761,7 @@ async fn run_route_chat(client: &mut RouteGuideClient<Channel>) -> Result<(), Bo
755761
let outbound = async_stream::stream! {
756762
let mut interval = time::interval(Duration::from_secs(1));
757763

758-
while let Some(time) = interval.next().await {
764+
while let time = interval.tick().await {
759765
let elapsed = time.duration_since(start);
760766
let note = RouteNote {
761767
location: Some(Point {

0 commit comments

Comments
 (0)