expression

Tonic: generate Rust bindings from a proto schema

The build script translates the schema into Rust message types and client/server interfaces. Include the package by its exact proto package name in a module. The generated item type is used below; the accompanying build.rs and lib.rs are essential prerequisites. Run in the accompanying generated-bindings Cargo project. Expected stdout (not executed): item 7 Common mistake: Trying to include a file before running the build script or using a module name instead of the proto package name.

Formal Syntax & Structure

rust syntaxrust
tonic_prost_build::compile_protos("proto/inventory.proto")?; tonic::include_proto!("bytemind.inventory.v1");

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    use bm_tonic_inventory::pb::GetItemRequest;    let message = GetItemRequest { id: 7 };    println!("item {}", message.id);}
Rust Reference