How can I include an arbitrary set of Protobuf-built files without knowing their names?

纵饮孤独 提交于 2019-12-11 05:59:13

问题


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;

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.

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).


回答1:


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

You can then include this file in your library with the include! macro.



来源:https://stackoverflow.com/questions/38504933/how-can-i-include-an-arbitrary-set-of-protobuf-built-files-without-knowing-their

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!