How can I include an arbitrary set of Protobuf-bui

2019-07-23 18:40发布

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条回答
爷、活的狠高调
2楼-- · 2019-07-23 18:43

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.

查看更多
登录 后发表回答