This change introduces proper gRPC interceptors that are avilable regardless of the transport used. Each codegen service now produces an additional method called `with_interceptor` that accepts a `Interceptor`. All examples have been updated to use this new style and interop has a custom `tower::Service` middleware to echo the headers. There is also a new `interceptor` example that shows basic usage. BREAKING CHANGE: removed `interceptor_fn` and `intercep_headers_fn` from `transport` in favor of using `tonic::Interceptor`.
tonic-build
Compiles proto files via prost and generates service stubs and proto definitiones for use with tonic.
Features
- rustfmt: This feature enables the use of rustfmt to format the output code this makes the code readable and the error messages nice. This requires that rustfmt is installed. This is enabled by default.
Required dependencies
[dependencies]
bytes = <bytes-version>
tonic = <tonic-version>
prost = <prost-version>
[build-dependencies]
tonic-build = <tonic-version>
Examples
Simple
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("proto/service.proto")?;
Ok(())
}
Configuration
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
.build_server(false)
.compile(
&["proto/helloworld/helloworld.proto"],
&["proto/helloworld"],
)?;
Ok(())
}