作者:手机用户2602903963 | 来源:互联网 | 2022-12-25 15:51
我试图按照说明生成Rust protobuffer文件:
用于生成.rs文件的API
用于生成.rs
要在build.rs中使用的文件的API .
示例代码:
extern crate protoc_rust;
protoc_rust::run(protoc_rust::Args {
out_dir: "src/protos",
input: &["protos/a.proto", "b.proto"],
includes: &["protos"], }).expect("protoc");
并在Cargo.toml
:
[build-dependencies]
protoc-rust = "1.4"
请注意,此API需要protoc
存在的命令$PATH
.虽然
protoc-gen-rust
不需要命令.
没有明确的文档说明这些参数的传递内容.第一个(out_dir
)显然是生成文件的目录.input
看起来像用于生成的文件 列表.proto
.在这个例子中,第一个有一个目录,而第二个没有.我是否需要为每个目录或第一个目录传递一个目录?includes
真让我困惑.这是要查看的文件夹列表吗?如果我在protos
这里添加,我可以省略它的元素input
吗?
1> Arjan..:
如果你看一下源代码(源代码),你会看到:
#[derive(Debug, Default)]
pub struct Args<'a> {
/// --lang_out= param
pub out_dir: &'a str,
/// -I args
pub includes: &'a [&'a str],
/// List of .proto files to compile
pub input: &'a [&'a str],
}
所以这些论点的含义是:
out_dir
:生成的文件的位置
includes
(-I
):protoc将搜索导入的位置(文档)
input
:.proto
要编译的文件列表