expression
Tonic: implement and call a generated unary service trait
The shared InventoryDemo implements the generated Inventory trait with a typed unary request and response. Calling the trait directly exercises handler logic only; no HTTP/2 transport, interceptor or server is involved. Run in the accompanying generated-bindings Cargo project. Expected stdout (not executed): 7: Notebook Common mistake: Calling a local handler a complete gRPC integration test.
Formal Syntax & Structure
rust syntaxrust
service.get_item(Request::new(message)).awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { use bm_tonic_inventory::{InventoryDemo, pb::{GetItemRequest, inventory_server::Inventory}}; use tonic::Request; let response = InventoryDemo.get_item(Request::new(GetItemRequest { id: 7 })).await.unwrap(); let item = response.into_inner(); println!("{}: {}", item.id, item.name);}