#protobuf #serialization #protocol-buffers #api #protoc

protoc-rust

protoc --rust_out=... available as API. protoc needs to be in $PATH, protoc-gen-run does not.

81 stable releases

3.0.0-alpha.2 Nov 1, 2021
2.28.0 Sep 26, 2022
2.27.1 Feb 5, 2022
2.25.2 Oct 24, 2021
1.4.1 Jun 24, 2017

#101 in #protobuf

Download history 16916/week @ 2022-08-14 21572/week @ 2022-08-21 19907/week @ 2022-08-28 17128/week @ 2022-09-04 20105/week @ 2022-09-11 21741/week @ 2022-09-18 17830/week @ 2022-09-25 19297/week @ 2022-10-02 15430/week @ 2022-10-09 20043/week @ 2022-10-16 18573/week @ 2022-10-23 18473/week @ 2022-10-30 19946/week @ 2022-11-06 18778/week @ 2022-11-13 14332/week @ 2022-11-20 23460/week @ 2022-11-27

77,783 downloads per month
Used in fewer than 52 crates

MIT license

1.5MB
35K SLoC

API to generate .rs files

API to generate .rs files to be used e. g. from build.rs.

Example code:

extern crate protoc_rust;

use protoc_rust::Customize;

fn main() {
    protoc_rust::Codegen::new()
        .out_dir("src/protos")
        .inputs(&["protos/a.proto", "protos/b.proto"])
        .include("protos")
        .run()
        .expect("protoc");
}

And in Cargo.toml:

[build-dependencies]
protoc-rust = "2.0"

Note 1: This API requires protoc command present in $PATH. Although protoc-gen-rust command is not needed.

Note 2: Is advisable that protoc-rust build-dependecy version be the same as protobuf dependency.

The alternative is to use pure-rust .proto parser and code generator.


lib.rs:

API to generate .rs files.

This API requires protoc command present in $PATH or passed explicitly to Codegen object.

extern crate protoc_rust;

fn main() {
    protoc_rust::Codegen::new()
        .out_dir("src/protos")
        .inputs(&["protos/a.proto", "protos/b.proto"])
        .include("protos")
        .run()
        .expect("Running protoc failed.");
}

It is advisable that protoc-rust build-dependecy version be the same as protobuf dependency.

The alternative is to use protobuf-codegen-pure.

Dependencies