[−][src]Struct pb_rs::ConfigBuilder
A builder for Config
Example buld.rs
extern crate pb_rs; extern crate walkdir; 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() }
Methods
impl ConfigBuilder
[src]
pub fn new<P: AsRef<Path>>(
in_files: &[P],
output: Option<&P>,
output_dir: Option<&P>,
include_paths: &[P]
) -> Result<ConfigBuilder>
[src]
in_files: &[P],
output: Option<&P>,
output_dir: Option<&P>,
include_paths: &[P]
) -> Result<ConfigBuilder>
pub fn single_module(self, val: bool) -> Self
[src]
Omit generation of modules for each package when there is only one package
pub fn no_output(self, val: bool) -> Self
[src]
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.
pub fn error_cycle(self, val: bool) -> Self
[src]
Error out if recursive messages do not have optional fields
pub fn headers(self, val: bool) -> Self
[src]
Enable module comments and module attributes in generated file (default = true)
pub fn custom_struct_derive(self, val: Vec<String>) -> Self
[src]
Add custom values to #[derive(...)] at the beginning of every structure
pub fn dont_use_cow(self, val: bool) -> Self
[src]
Use Cow<,> for Strings and Bytes
pub fn owned(self, val: bool) -> Self
[src]
Generate Owned structs when the proto stuct has a lifetime
pub fn build(self) -> Vec<Config>
[src]
Build Config from this ConfigBuilder
Trait Implementations
impl Default for ConfigBuilder
[src]
fn default() -> ConfigBuilder
[src]
impl Debug for ConfigBuilder
[src]
Auto Trait Implementations
impl Send for ConfigBuilder
impl Sync for ConfigBuilder
impl Unpin for ConfigBuilder
impl UnwindSafe for ConfigBuilder
impl RefUnwindSafe for ConfigBuilder
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,