Skip to content

Commit 18c20a9

Browse files
authored
chore(readme): Remove readme examples (mozilla#79)
* chore(readme): Remove readme examples This swaps out the readme example to use instead a link to the routeguide tutorial. * Add helloworld tutorial
1 parent 8ebedcd commit 18c20a9

1 file changed

Lines changed: 6 additions & 126 deletions

File tree

README.md

Lines changed: 6 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -46,133 +46,11 @@ $ rustup component add rustfmt --toolchain beta
4646
$ cargo +beta build
4747
```
4848

49-
### Examples
49+
### Tutorials
5050

51-
<details>
52-
<summary>Helloworld</summary>
53-
54-
#### `Cargo.toml`
55-
56-
```toml
57-
edition = "2018"
58-
59-
[dependencies]
60-
tonic = "*"
61-
bytes = "0.4"
62-
prost = "0.5"
63-
prost-derive = "0.5"
64-
65-
[build-dependencies]
66-
tonic-build = "*"
67-
```
68-
69-
#### Protobuf
70-
71-
```protobuf
72-
package helloworld;
73-
74-
// The greeting service definition.
75-
service Greeter {
76-
// Sends a greeting
77-
rpc SayHello (HelloRequest) returns (HelloReply) {}
78-
}
79-
80-
// The request message containing the user's name.
81-
message HelloRequest {
82-
string name = 1;
83-
}
84-
85-
// The response message containing the greetings
86-
message HelloReply {
87-
string message = 1;
88-
}
89-
```
90-
91-
#### `build.rs`
92-
93-
```rust
94-
fn main() {
95-
tonic_build::compile_protos("proto/helloworld/helloworld.proto").unwrap();
96-
}
97-
```
98-
99-
#### Client
100-
101-
```rust
102-
pub mod hello_world {
103-
tonic::include_proto!("helloworld");
104-
}
105-
106-
use hello_world::{client::GreeterClient, HelloRequest};
107-
108-
#[tokio::main]
109-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
110-
let mut client = GreeterClient::connect("http://[::1]:50051")?;
111-
112-
let request = tonic::Request::new(HelloRequest {
113-
name: "hello".into(),
114-
});
115-
116-
let response = client.say_hello(request).await?;
117-
118-
println!("RESPONSE={:?}", response);
119-
120-
Ok(())
121-
}
122-
```
123-
124-
#### Server
125-
126-
```rust
127-
use tonic::{transport::Server, Request, Response, Status};
128-
129-
pub mod hello_world {
130-
tonic::include_proto!("helloworld");
131-
}
132-
133-
use hello_world::{
134-
server::{Greeter, GreeterServer},
135-
HelloReply, HelloRequest,
136-
};
137-
138-
#[derive(Default)]
139-
pub struct MyGreeter {
140-
data: String,
141-
}
142-
143-
#[tonic::async_trait]
144-
impl Greeter for MyGreeter {
145-
async fn say_hello(
146-
&self,
147-
request: Request<HelloRequest>,
148-
) -> Result<Response<HelloReply>, Status> {
149-
println!("Got a request: {:?}", request);
150-
151-
let string = &self.data;
152-
153-
println!("My data: {:?}", string);
154-
155-
let reply = hello_world::HelloReply {
156-
message: "Zomg, it works!".into(),
157-
};
158-
Ok(Response::new(reply))
159-
}
160-
}
161-
162-
#[tokio::main]
163-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
164-
let addr = "[::1]:50051".parse().unwrap();
165-
let greeter = MyGreeter::default();
166-
167-
Server::builder()
168-
.serve(addr, GreeterServer::new(greeter))
169-
.await?;
170-
171-
Ok(())
172-
}
173-
```
174-
175-
</details>
51+
- The [`helloworld`][helloworld-tutorial] tutorial provides a basic example of using `tonic`, prefect for first time users!
52+
- The [`routeguide`][routeguide-tutorial] tutorial provides a complete example of using `tonic` and all its
53+
features.
17654

17755
## Getting Help
17856

@@ -226,3 +104,5 @@ terms or conditions.
226104
[Website]: https://github.com/hyperium/tonic
227105
[Docs]: https://docs.rs/tonic
228106
[Chat]: https://discord.gg/6yGkFeN
107+
[routeguide-tutorial]: https://github.com/hyperium/tonic/blob/master/tonic-examples/routeguide-tutorial.md
108+
[hellworld-tutorial]: https://github.com/hyperium/tonic/blob/master/tonic-examples/helloworld-tutorial.md

0 commit comments

Comments
 (0)