pub struct ConfigBuilder { /* private fields */ }
Expand description
A builder for Config
§Example build.rs
use pb_rs::{types::FileDescriptor, ConfigBuilder};
use std::path::{Path, PathBuf};
use walkdir::WalkDir;
fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();
let out_dir = Path::new(&out_dir).join("protos");
let in_dir = PathBuf::from(::std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("protos");
// Re-run this build.rs if the protos dir changes (i.e. a new file is added)
println!("cargo:rerun-if-changed={}", in_dir.to_str().unwrap());
// Find all *.proto files in the `in_dir` and add them to the list of files
let mut protos = Vec::new();
let proto_ext = Some(Path::new("proto").as_os_str());
for entry in WalkDir::new(&in_dir) {
let path = entry.unwrap().into_path();
if path.extension() == proto_ext {
// Re-run this build.rs if any of the files in the protos dir change
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
protos.push(path);
}
}
// Delete all old generated files before re-generating new ones
if out_dir.exists() {
std::fs::remove_dir_all(&out_dir).unwrap();
}
std::fs::DirBuilder::new().create(&out_dir).unwrap();
let config_builder = ConfigBuilder::new(&protos, None, Some(&out_dir), &[in_dir]).unwrap();
FileDescriptor::run(&config_builder.build()).unwrap()
}
Implementations§
Source§impl ConfigBuilder
impl ConfigBuilder
pub fn new<P: AsRef<Path>>( in_files: &[P], output: Option<&P>, output_dir: Option<&P>, include_paths: &[P], ) -> Result<ConfigBuilder>
Sourcepub fn single_module(self, val: bool) -> Self
pub fn single_module(self, val: bool) -> Self
Omit generation of modules for each package when there is only one package
Sourcepub fn no_output(self, val: bool) -> Self
pub fn no_output(self, val: bool) -> Self
Show enums and messages in this .proto file, including those imported. No code generated.
no_output
should probably only be used by the pb-rs cli.
Sourcepub fn error_cycle(self, val: bool) -> Self
pub fn error_cycle(self, val: bool) -> Self
Error out if recursive messages do not have optional fields
Sourcepub fn headers(self, val: bool) -> Self
pub fn headers(self, val: bool) -> Self
Enable module comments and module attributes in generated file (default = true)
Sourcepub fn custom_struct_derive(self, val: Vec<String>) -> Self
pub fn custom_struct_derive(self, val: Vec<String>) -> Self
Add custom values to #[derive(...)]
at the beginning of every structure
Sourcepub fn custom_repr(self, val: Option<String>) -> Self
pub fn custom_repr(self, val: Option<String>) -> Self
Add custom values to #[repr(...)]
at the beginning of every structure
Sourcepub fn dont_use_cow(self, val: bool) -> Self
pub fn dont_use_cow(self, val: bool) -> Self
Use Cow<_,_>
for Strings and Bytes
Sourcepub fn owned(self, val: bool) -> Self
pub fn owned(self, val: bool) -> Self
Generate Owned structs when the proto struct has a lifetime
Sourcepub fn hashbrown(self, val: bool) -> Self
pub fn hashbrown(self, val: bool) -> Self
Use hashbrown as HashMap
implementation instead of std::collections::HashMap or
alloc::collections::BTreeMap
in a no_std
environment
Sourcepub fn add_deprecated_fields(self, val: bool) -> Self
pub fn add_deprecated_fields(self, val: bool) -> Self
Add deprecated fields and mark them as #[deprecated]