architect_tonic/
lib.rs

1//! A Rust implementation of [gRPC], a high performance, open source, general
2//! RPC framework that puts mobile and HTTP/2 first.
3//!
4//! [`tonic`] is a gRPC over HTTP/2 implementation focused on **high
5//! performance**, **interoperability**, and **flexibility**. This library was
6//! created to have first class support of async/await and to act as a core building
7//! block for production systems written in Rust.
8//!
9//! # Examples
10//!
11//! Examples can be found in the [`tonic-examples`] crate.
12//!
13//! # Getting Started
14//!
15//! Follow the instructions in the [`tonic-build`] crate documentation.
16//!
17//! # Feature Flags
18//!
19//! - `transport`: Enables the fully featured, batteries included client and server
20//!   implementation based on [`hyper`], [`tower`] and [`tokio`]. This enables `server`
21//!   and `channel` features. Enabled by default.
22//! - `server`: Enables just the full featured server portion of the `transport` feature.
23//! - `channel`: Enables just the full featured channel portion of the `transport` feature.
24//! - `router`: Enables the [`axum`] based service router. Enabled by default.
25//! - `codegen`: Enables all the required exports and optional dependencies required
26//!   for [`tonic-build`]. Enabled by default.
27//! - `tls`: Deprecated. An alias to `tls-ring`
28//! - `tls-ring`: Enables the [`rustls`] based TLS options for the `transport` feature using
29//!   the [`ring`]` libcrypto provider. Not enabled by default.
30//! - `tls-aws-lc`: Enables the [`rustls`] based TLS options for the `transport` feature using
31//!   the [`aws-lc-rs`] libcrypto provider. Not enabled by default.
32//! - `tls-roots`: Deprecated. An alias to `tls-native-roots` feature.
33//! - `tls-native-roots`: Adds system trust roots to [`rustls`]-based gRPC clients using the
34//!   [`rustls-native-certs`] crate. Not enabled by default.
35//! - `tls-webpki-roots`: Add the standard trust roots from the [`webpki-roots`] crate to
36//!   `rustls`-based gRPC clients. Not enabled by default.
37//! - `prost`: Enables the [`prost`] based gRPC [`Codec`] implementation. Enabled by default.
38//! - `gzip`: Enables compressing requests, responses, and streams. Depends on [`flate2`].
39//!   Not enabled by default.
40//! - `zstd`: Enables compressing requests, responses, and streams. Depends on [`zstd`].
41//!   Not enabled by default.
42//!
43//! # Structure
44//!
45//! ## Generic implementation
46//!
47//! The main goal of [`tonic`] is to provide a generic gRPC implementation over HTTP/2
48//! framing. This means at the lowest level this library provides the ability to use
49//! a generic HTTP/2 implementation with different types of gRPC encodings formats. Generally,
50//! some form of codegen should be used instead of interacting directly with the items in
51//! [`client`] and [`server`].
52//!
53//! ## Transport
54//!
55//! The [`transport`] module contains a fully featured HTTP/2.0 [`Channel`] (gRPC terminology)
56//! and [`Server`]. These implementations are built on top of [`tokio`], [`hyper`] and [`tower`].
57//! It also provides many of the features that the core gRPC libraries provide such as load balancing,
58//! tls, timeouts, and many more. This implementation can also be used as a reference implementation
59//! to build even more feature rich clients and servers. This module also provides the ability to
60//! enable TLS using [`rustls`], via the `tls` feature flag.
61//!
62//! # Code generated client/server configuration
63//!
64//! ## Max Message Size
65//!
66//! Currently, both servers and clients can be configured to set the max message encoding and
67//! decoding size. This will ensure that an incoming gRPC message will not exhaust the systems
68//! memory. By default, the decoding message limit is `4MB` and the encoding limit is `usize::MAX`.
69//!
70//! [gRPC]: https://grpc.io
71//! [`tonic`]: https://github.com/hyperium/tonic
72//! [`tokio`]: https://docs.rs/tokio
73//! [`prost`]: https://docs.rs/prost
74//! [`hyper`]: https://docs.rs/hyper
75//! [`tower`]: https://docs.rs/tower
76//! [`tonic-build`]: https://docs.rs/tonic-build
77//! [`ring`]: https://docs.rs/ring
78//! [`tonic-examples`]: https://github.com/hyperium/tonic/tree/master/examples
79//! [`Codec`]: codec/trait.Codec.html
80//! [`Channel`]: transport/struct.Channel.html
81//! [`Server`]: transport/struct.Server.html
82//! [`rustls`]: https://docs.rs/rustls
83//! [`client`]: client/index.html
84//! [`transport`]: transport/index.html
85//! [`rustls-native-certs`]: https://docs.rs/rustls-native-certs
86//! [`webpki-roots`]: https://docs.rs/webpki-roots
87//! [`flate2`]: https://docs.rs/flate2
88//! [`zstd`]: https://docs.rs/zstd
89
90#![recursion_limit = "256"]
91#![warn(
92    missing_debug_implementations,
93    missing_docs,
94    rust_2018_idioms,
95    unreachable_pub
96)]
97#![deny(rustdoc::broken_intra_doc_links)]
98#![doc(
99    html_logo_url = "https://raw.githubusercontent.com/tokio-rs/website/master/public/img/icons/tonic.svg"
100)]
101#![doc(html_root_url = "https://docs.rs/tonic/0.13.0")]
102#![doc(issue_tracker_base_url = "https://github.com/hyperium/tonic/issues/")]
103#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
104#![cfg_attr(docsrs, feature(doc_auto_cfg))]
105
106pub mod body;
107pub mod client;
108pub mod codec;
109pub mod metadata;
110pub mod server;
111pub mod service;
112
113#[cfg(any(feature = "server", feature = "channel"))]
114pub mod transport;
115
116mod extensions;
117mod macros;
118mod request;
119mod response;
120mod status;
121mod util;
122
123/// A re-export of [`async-trait`](https://docs.rs/async-trait) for use with codegen.
124#[cfg(feature = "codegen")]
125pub use async_trait::async_trait;
126
127#[doc(inline)]
128pub use codec::Streaming;
129pub use extensions::GrpcMethod;
130pub use http::Extensions;
131pub use request::{IntoRequest, IntoStreamingRequest, Request};
132pub use response::Response;
133pub use status::{Code, ConnectError, Status, TimeoutExpired};
134
135pub(crate) type BoxError = Box<dyn std::error::Error + Send + Sync>;
136
137#[doc(hidden)]
138#[cfg(feature = "codegen")]
139pub mod codegen;
140
141/// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]).
142/// By default, the Err value is of type [`Status`] but this can be overridden if desired.
143pub type Result<T, E = Status> = std::result::Result<T, E>;