expression

gRPC: service, method and message contract

A gRPC service declares remotely callable operations and their input/output types. The accompanying inventory.proto defines GetItem. This local function mirrors its shape without a network or generated client. Actual RPC calls can fail independently of application logic. Expected stdout (not executed): 7: Notebook Common mistake: Treating a remote call as infallible just because it looks like a local function.

Formal Syntax & Structure

rust syntaxrust
rpc GetItem(GetItemRequest) returns (ItemReply);

Working Example

Example Snippetrust
fn main() {    struct GetItemRequest { id: u64 }    struct ItemReply { id: u64, name: String }    fn get_item(req: GetItemRequest) -> Option<ItemReply> {        (req.id == 7).then(|| ItemReply { id: req.id, name: "Notebook".into() })    }    let item = get_item(GetItemRequest { id: 7 }).unwrap();    println!("{}: {}", item.id, item.name);}
Rust Reference