expression

Tonic: create a generated client without connecting

A generated client can be constructed with a Channel from a lazy endpoint. No RPC is issued here; lazy construction does not demonstrate a reachable server or a successful handshake. The synthetic loopback address is intentionally not contacted. Run in the accompanying generated-bindings Cargo project. Expected stdout (not executed): client configured; no RPC sent Common mistake: Assuming a lazy channel proves that a server is online or using plaintext for external production traffic.

Formal Syntax & Structure

rust syntaxrust
InventoryClient::new(Endpoint::from_static(uri).connect_lazy())

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    use bm_tonic_inventory::pb::inventory_client::InventoryClient;    use tonic::transport::Endpoint;    let endpoint = Endpoint::from_static("http://127.0.0.1:50051");    let _client = InventoryClient::new(endpoint.connect_lazy());    println!("client configured; no RPC sent");}
Rust Reference