1 个稳定版本
使用旧的 Rust 2015
| 2.0.4 | 2018 年 12 月 19 日 |
|---|
在 开发工具 中排名 #2170
每月下载量 30
在 protoc-rust-no-elision 中使用
1.5MB
32K SLoC
protobuf-codegen
此包包含 protobuf 代码生成器和 protoc-gen-rust protoc 插件。
protoc-gen-rust
protoc-gen-rust 实现了标准的 protobuf protoc 插件约定。
你可能不希望在 Rust 环境中直接使用它,有更易用的替代方案
- protoc-rust 包,它可以从项目的
build.rs中程序性地调用,只需要protoc,但不需要protoc-gen-rust。 - protobuf-codegen-pure 包,它的工作方式类似于 protoc-rust,但不依赖于
protoc二进制文件
但如果你确实想使用该插件,以下是如何使用它的说明
(注意 protoc 可以通过 protoc 包 程序化调用)
- 安装
protoc的 protobuf 二进制文件。
在 OS X 上可以使用 Homebrew
brew install protobuf
在 Ubuntu 上,可以安装 protobuf-compiler 软件包
apt-get install protobuf-compiler
只需要 protobuf 用于代码生成,rust-protobuf 运行时不使用 protobuf 库。
- 安装
protoc-gen-rust程序(它是protoc插件)
它可以从源代码安装,也可以使用 cargo install protobuf 命令安装。
- 将
protoc-gen-rust添加到 $PATH
如果您使用 cargo 安装,它应该是
PATH="$HOME/.cargo/bin:$PATH"
- 生成 .rs 文件
protoc --rust_out . foo.proto
这将生成当前目录中的 .rs 文件。