--- url: "https://grpc.io/docs/languages/rust/quickstart/" titulek: "Quick start | Rust | gRPC" h1: "Quick start" popis: "This guide gets you started with gRPC in Rust with a simple working example." jazyk: "en" kanonicka: "https://grpc.io/docs/languages/rust/quickstart/" drobecky: ["Docs", "Languages", "Rust", "Quick start"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 20:59:49" znaku: 8581 slov: 1015 kodovani: "utf-8" sha256: "6e3582cd37d653c680e09e30218a6565d7501bd2ab4652bca8c6636ad479711b" --- # Quick start This guide gets you started with gRPC in Rust with a simple working example. Contents # Quick start This guide gets you started with gRPC in Rust with a simple working example. ### Prerequisites - **[Rust](https://rust-lang.org/)**, any version supported by the current [gRPC-Rust MSRV](https://github.com/grpc/grpc-rust#rust-version). For installation instructions, see Rust’s [Getting Started](https://rust-lang.org/learn/get-started/) guide. - **Protobuf code generation tools** There are two tools used to generate the Rust protobuf code: There are two options for installing these tools. **NOTE:** For now, to run the examples, which share some setup code with `tonic`, you *must* ensure `protoc` is in your `PATH` or set the `PROTOC` environment variable to your `protoc` executable’s path. 1. **[Protocol buffer](https://protobuf.dev/) compiler** , `protoc` , [version 34.0](https://github.com/protocolbuffers/protobuf/releases/tag/v34.0) . This generates the defined *message* data structures. 2. **gRPC-Rust plugin** , `protoc-gen-rust-grpc` This generates the defined *services* and *methods* . 1. A C++17 compatible compiler and CMake 3.14 or higher are required to compile the protobuf code generation tool. 2. Alternatively, compiled versions of the tools can be downloaded from the [protobuf releases](https://github.com/protocolbuffers/protobuf/releases) (for `protoc` ) and [grpc releases](https://github.com/grpc/grpc-rust/releases) (for `protoc-gen-rust-grpc` ) GitHub pages. - For this option, be sure to update your `PATH` to include both of the binaries. - For `protoc` installation instructions, see [Protocol Buffer Compiler Installation](/docs/protoc-installation/) . Note that because Rust support in `protoc` is not yet stable, **the version installed must be exactly 34.0.** ### Get the example code The example code is part of the [grpc-rust](https://github.com/grpc/grpc-rust) repo. 1. [Download the repo as a zip file](https://github.com/grpc/grpc-rust/archive/grpc-v0.9.0.zip) and unzip it, or clone the repo: `git clone -b grpc-v0.9.0 --depth 1 https://github.com/grpc/grpc-rust` 2. Change to the `examples` directory: `cd grpc-rust/examples` ### Run the example From the `examples` directory: 1. Compile and execute the server code: `cargo run --bin helloworld-server` 2. From a different terminal, compile and execute the client code to see the client output: `cargo run --bin grpc-helloworld-client Greeting: Hello world` Congratulations! You’ve just run a client-server application with gRPC. ### Update the gRPC service In this section you’ll update the application with an extra server method. The gRPC service is defined using [protocol buffers](https://protobuf.dev/). To learn more about how to define a service in a `.proto` file see [Basics tutorial](../basics/). For now, all you need to know is that both the server and the client stub have a `SayHello()` RPC method that takes a `HelloRequest` parameter from the client and returns a `HelloReply` from the server, and that the method is defined like this: ``` // The greeting service definition. service Greeter { // Sends a greeting rpc SayHello (HelloRequest) returns (HelloReply) {} } // The request message containing the user's name. message HelloRequest { string name = 1; } // The response message containing the greetings message HelloReply { string message = 1; } ``` Open `proto/helloworld/helloworld.proto` and add a new `SayHelloAgain()` method, with the same request and response types: ``` // The greeting service definition. service Greeter { // Sends a greeting rpc SayHello (HelloRequest) returns (HelloReply) {} // Sends another greeting rpc SayHelloAgain (HelloRequest) returns (HelloReply) {} } // The request message containing the user's name. message HelloRequest { string name = 1; } // The response message containing the greetings message HelloReply { string message = 1; } ``` Remember to save the file! ### Regenerate gRPC code Before you can use the new service method, you need to recompile the updated `.proto` file. From the `examples/` directory, run the following: 1. If you installed `protoc` and `protoc-gen-rust-grpc` into your path: ``` GRPC_RUST_REGENERATE_PROTO=1 cargo build --bin grpc-routeguide-client ``` 1. If you prefer to build these tools from source with a C++ compiler and CMake as described above: ``` GRPC_RUST_REGENERATE_PROTO=1 cargo build --bin grpc-routeguide-client --features grpc-protobuf-build/build-plugin ``` This will regenerate the `generated.rs`, `helloworld.u.pb.rs`, and `helloworld_grpc.pb.rs` files in `src/grpc-helloworld/generated/`, which contain: - Code for populating, serializing, and retrieving `HelloRequest` and `HelloReply` message types. - Generated client code. **How does this work?** We are leveraging the `grpc-protobuf-build` crate in `examples/build.rs` to perform the code generation step. However, this is only executed when you are running one of our grpc-based examples *and* when the environment variable `GRPC_RUST_REGENERATE_PROTO` is set. That is, in `examples/build.rs` you will see something like: ``` if env::var_os("GRPC_RUST_REGENERATE_PROTO").is_some() { grpc_protobuf_build::CodeGen::new() .output_dir(manifest_dir.join("src/grpc-helloworld/generated")) .input("helloworld.proto") .include(manifest_dir.join("proto/helloworld")) .client_only() .compile() .unwrap(); } ``` You can run `protoc` manually, instead, to perform code generation if you don’t wish to use build.rs integration. To do that, you would use: ``` protoc --rust_out=src/grpc-helloworld/generated/ --rust_opt=experimental-codegen=enabled,kernel=upb \ --rust-grpc_out=src/grpc-helloworld/generated/ --rust-grpc_opt=client_only=true \ --proto_path=proto/helloworld/ proto/helloworld/helloworld.proto ``` ### Update and run the application You have regenerated the server and client code, but you still need to implement and call the new method in the human-written parts of the example application. #### Update the server Open `src/helloworld/server.rs` (the legacy Tonic server) and add the following function to the `impl Greeter for MyGreeter` block: ``` async fn say_hello_again( &self, request: Request, ) -> Result, Status> { println!("Got a request from {:?}", request.remote_addr()); let reply = hello_world::HelloReply { message: format!("Hello again {}!", request.into_inner().name), }; Ok(Response::new(reply)) } ``` #### Update the client Open `src/grpc-helloworld/client.rs` to add the following code to the end of the `main()` function body: ``` let response = client.say_hello_again(request).await.expect("RPC error"); println!("Greeting: {:}", response.message()); ``` Remember to save your changes. #### Run! Run the client and server like you did before. Execute the following commands from the `examples/` directory: 1. Run the server: `cargo run --bin helloworld-server` 2. From another terminal, run the client. This time, add a name as a command-line argument: `cargo run --bin grpc-helloworld-client Alice Greeting: Hello Alice! Greeting: Hello again Alice!` ### What’s next - Learn how gRPC works in [Introduction to gRPC](/docs/what-is-grpc/introduction/) and [Core concepts](/docs/what-is-grpc/core-concepts/) . - Work through the [Basics tutorial](../basics/) . - Explore the [API reference](../api) . Last modified May 28, 2026: [Add grpc-rust documentation: language landing page, quickstart, and route guide (#1517) (5cfba73)](https://github.com/grpc/grpc.io/commit/5cfba733cb9f0817292bfc9124294190c66cccf7) [View page source](https://github.com/grpc/grpc.io/tree/main/content/en/docs/languages/rust/quickstart.md) [Edit this page](https://github.com/grpc/grpc.io/edit/main/content/en/docs/languages/rust/quickstart.md) [Create child page](https://github.com/grpc/grpc.io/new/main/content/en/docs/languages/rust/quickstart.md?filename=change-me.md&value=---%0Atitle%3A+%22Long+Page+Title%22%0AlinkTitle%3A+%22Short+Nav+Title%22%0Aweight%3A+100%0Adescription%3A+%3E-%0A+++++Page+description+for+heading+and+indexes.%0A---%0A%0A%23%23+Heading%0A%0AEdit+this+template+to+create+your+new+page.%0A%0A%2A+Give+it+a+good+name%2C+ending+in+%60.md%60+-+e.g.+%60getting-started.md%60%0A%2A+Edit+the+%22front+matter%22+section+at+the+top+of+the+page+%28weight+controls+how+its+ordered+amongst+other+pages+in+the+same+directory%3B+lowest+number+first%29.%0A%2A+Add+a+good+commit+message+at+the+bottom+of+the+page+%28%3C80+characters%3B+use+the+extended+description+field+for+more+detail%29.%0A%2A+Create+a+new+branch+so+you+can+preview+your+new+file+and+request+a+review+via+Pull+Request.%0A) [Create documentation issue](https://github.com/grpc/grpc.io/issues/new?title=Quick%20start) [Create project issue](https://github.com/grpc/grpc.io/issues/new)