A simple converter from .proto files into rust quick-protobuf compatible modules.
pb-rs <file.proto>
pb-rs can also be used as a crate (for example in your cargo build scripts).
```rust // Cargo.toml
[dependencies] quick-protobuf = "0.6.3"
[build-dependencies] pb-rs = "0.6.0"
// build.rs
extern crate pb_rs;
use std::path::{Path, PathBuf}; use pb_rs::types::{Config, FileDescriptor}; use std::env;
fn main() { let outdir = env::var("OUTDIR").unwrap(); let outfile = Path::new(outdir).join("hello.rs");
let config = Config {
in_file: PathBuf::from("protos/Hello.proto"),
out_file,
single_module: false,
import_search_path: vec![PathBuf::from("protos")],
no_output: false,
error_cycle: false, // may change a required field to an optional
headers: false, // do not generate headers
};
FileDescriptor::write_proto(&config).unwrap();
}
// main.rs or lib.rs
mod hello { includebytes!(concat!(env!("OUTDIR")), "/hello.rs"); } ```