[][src]Crate tonic_build

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]
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(())
}

Modules

client

Service code generation for client

server

Service code generation for Server

Structs

Builder

Service generator builder.

Traits

Method

Method generation trait.

Service

Service generation trait.

Functions

compile_protos

Simple .proto compiling. Use configure instead if you need more options.

configure

Configure tonic-build code generation.

fmt

Format files under the out_dir with rustfmt