提问人:Goldie 提问时间:7/7/2023 更新时间:7/7/2023 访问量:102
在 Rust 中生成代码的文件结构
File structure for generated code in Rust
问:
我正在使用 neoeinstein-prost buf 插件为我的 Rust 项目生成 protobuf 代码,到目前为止,该插件对我的用例运行良好。我的问题是生成的 *.rs 文件的惯用位置在哪里?这是工作区的用例吗(到目前为止,对于这个项目,我不需要)?
有几个选项对我有用,但可能不是惯用的(在每种情况下都包含原型规范和生成的输出):proto
gen
选项 1
此选项的优点是生成的代码规范和输出与手工制作的代码明显分开。缺点是指向主树外部的讨厌指令。path
src
- examples (uses lib)
- gen
|- src
| |- my_model.v1.rs
| |- my_model.v1.serde.rs (gets !included by my_model.v1.rs)
- proto
|- my_model
| |- v1
| | |- my_model.proto
- src
|- main.rs (uses lib)
|- lib
| |- lib.rs (exports "model" module using #[path = "../../gen/src/my_model.v1.rs"]
选项 2
此选项的优点是所有 lib 代码都是独立的,无论是手工制作的还是生成的。缺点是您需要去寻找生成的代码 - 它并不那么明显。
- examples (uses lib)
- proto
|- my_model
| |- v1
| | |- my_model.proto
- src
|- main.rs (uses lib)
|- lib
| |- lib.rs (exports "model" module using #[path = "gen/src/my_model.v1.rs"]
| |- gen
| | |- src (unnecessary level?)
| | | |- my_model.v1.rs
| | | |- my_model.v1.serde.rs (gets !included by my_model.v1.rs)
答: 暂无答案
评论
prost-build
的默认行为。build.rs
target
OUT_DIR