如何在不知道名称的情况下包含一组任意的 Protobuf 构建文件? [英] How can I include an arbitrary set of Protobuf-built files without knowing their names?
问题描述
我打算使用 rust-protobuf 库.我编写了一个 bash 脚本来构建所有内容(包括我的代码)并将我拥有的 .proto 文件构建到 .rs 文件中.文档告诉我继续的方式是专门做:
I'm planning on using the rust-protobuf library. I've written a bash script that builds everything (including my code) and builds the .proto files I have into .rs files. The way the documentation tells me to proceed is to specifically just do:
mod foo;
对于生成的每个 .rs 文件.我希望我的用户可以将新的 .proto 文件放入一个目录中,运行构建脚本,我的代码将负责包含已编译 .proto 文件的所有 Rust 实现.
for each of the .rs files generated. I'm hoping that my users can just drop in new .proto files into a directory, run the build script, and my code will take care of including all of the Rust implementations of the compiled .proto files.
我知道 Rust 并不真正支持反射,所以有什么方法可以基本上确定目录中所有 .rs 生成的文件并在我的代码中使用它们"(在 TLDR 语句中).
I know Rust doesn't really support reflection, so is there some way I can essentially "determine all the .rs generated files in a directory and use them in my code" (in a TLDR statement).
推荐答案
你可以写一个 Cargo build脚本 它将扫描您的目录并生成一个如下所示的 Rust 文件:
You could write a Cargo build script which would scan your directory and generate a Rust file that looks like:
mod file1;
mod file2;
//etc
然后您可以使用 include 将此文件包含在您的库中!
宏.
You can then include this file in your library with the include!
macro.
这篇关于如何在不知道名称的情况下包含一组任意的 Protobuf 构建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!