API Reference

Tonic

Fast gRPC implementation for Rust with async code generation, streaming and interceptors.

Official Documentation ↗
CompatibilityThis documentation covers version tonic 0.12 / Rust 1.70+(基于 hyper 与 tokio). Check the official docs for the latest API surface.

Installation

cargocargo add tonic

Methods

Overview

Tonic is a high-performance gRPC framework for Rust. It generates async client and server code from proto definitions, supports streaming, and composes with Tower middleware.

Core Methods

Build servers with Server::builder and add_service, connect clients with generated Client types, and apply interceptors or layers for cross-cutting concerns.

Usage Notes

Generate code at build time with tonic-build, apply tracing and timeout layers, and return proper gRPC status codes. Use Tower layers for retries and limits on clients.

Common Pitfalls

Missing deadlines lets slow calls accumulate. Interceptor ordering affects behavior. Generating code manually instead of at build time causes drift, and inconsistent status codes confuse clients.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://docs.rs/tonic/latest/tonic/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:53:02.076Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

How is Tonic different from grpcio?
Tonic is a pure-Rust, async, tokio-based gRPC implementation that integrates with Tower, whereas grpcio wraps the C core. Tonic fits Rust async ecosystems naturally.
How do I handle streaming?
Generated clients and servers expose streaming methods using tokio Stream types, letting you send and receive streams of messages over one call.
How do I propagate deadlines?
Tonic supports request timeouts through the request ext and Tower timeout layers. Set timeouts and check status codes on the client to avoid hanging calls.