Skip to main content

Crate ttrpc_codegen

Crate ttrpc_codegen 

Source
Expand description

Pure-Rust build-time code generation for ttrpc services.

ttrpc-codegen parses .proto files and generates Protocol Buffers messages, typed ttrpc clients, server traits, and registration helpers. It does not require a protoc executable.

Add this crate under [build-dependencies] and invoke Codegen from build.rs.

§Examples

use ttrpc_codegen::{Codegen, Customize, ProtobufCustomize};

Codegen::new()
    .out_dir(std::env::var("OUT_DIR").expect("OUT_DIR is set for build scripts"))
    .input("proto/greeter.proto")
    .include("proto")
    .rust_protobuf()
    .customize(Customize {
        async_all: true,
        gen_mod: true,
        ..Default::default()
    })
    .rust_protobuf_customize(ProtobufCustomize::default().gen_mod_rs(true))
    .run()?;

When no output directory is configured, Codegen::run uses Cargo’s OUT_DIR environment variable. Generated module declarations can then be included with:

ⓘ
include!(concat!(env!("OUT_DIR"), "/mod.rs"));

Structs§

Codegen
Builder for pure-Rust Protocol Buffers and ttrpc code generation.
Customize
Customize generated code.
ProtobufCustomize
Specifies style of generated code. Generated files can be customized using this proto or using rustproto.proto options.

Traits§

ProtobufCustomizeCallback
Dynamic callback to customize code generation.