[][src]Struct pb_rs::ConfigBuilder

pub struct ConfigBuilder { /* fields omitted */ }

A builder for Config

Example buld.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

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]

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 custom_repr(self, val: Option<String>) -> Self[src]

Add custom values to #[repr(...)] 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 nostd(self, val: bool) -> Self[src]

Generate no_std compliant code

pub fn hashbrown(self, val: bool) -> Self[src]

Use hashbrown as HashMap implementation instead of std::collections::HashMap or [alloc::collections::BTreeMap] in a no_std environment

pub fn build(self) -> Vec<Config>[src]

Build Config from this ConfigBuilder

Trait Implementations

impl Debug for ConfigBuilder[src]

impl Default for ConfigBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.