81 个稳定版本
| 3.0.0-alpha.2 | 2021年11月1日 |
|---|---|
| 2.28.0 | 2022年9月26日 |
| 2.27.1 | 2022年2月5日 |
| 2.25.2 | 2021年10月24日 |
| 1.4.1 | 2017年6月24日 |
#17 在 #protoc 中
20,065 每月下载量
在 少于 55 crates 中使用
2MB
41K SLoC
生成 .rs 文件的 API
生成 .rs 文件的 API,可用于例如 从 build.rs 中。
示例代码
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");
}
在 Cargo.toml 中
[build-dependencies]
protoc-rust = "2.0"
注意 1:此 API 需要 protoc 命令存在于 $PATH 中。尽管不需要 protoc-gen-rust 命令。
注意 2:建议将 protoc-rust 的构建依赖版本与 protobuf 依赖版本相同。
另一种选择是使用 纯 Rust .proto 解析器和代码生成器。
lib.rs:
生成 .rs 文件的 API。
此 API 需要 protoc 命令存在于 $PATH 中,或者显式传递给 Codegen 对象。
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.");
}
建议将 protoc-rust 的构建依赖版本与 protobuf 依赖版本相同。
另一种选择是使用 protobuf-codegen-pure。
依赖
~2–11MB
~130K SLoC