Struct ConfigBuilder

Source
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

Source

pub fn new<P: AsRef<Path>>( in_files: &[P], output: Option<&P>, output_dir: Option<&P>, include_paths: &[P], ) -> Result<ConfigBuilder>

Source

pub fn single_module(self, val: bool) -> Self

Omit generation of modules for each package when there is only one package

Source

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.

Source

pub fn error_cycle(self, val: bool) -> Self

Error out if recursive messages do not have optional fields

Source

pub fn headers(self, val: bool) -> Self

Enable module comments and module attributes in generated file (default = true)

Source

pub fn custom_struct_derive(self, val: Vec<String>) -> Self

Add custom values to #[derive(...)] at the beginning of every structure

Source

pub fn custom_repr(self, val: Option<String>) -> Self

Add custom values to #[repr(...)] at the beginning of every structure

Source

pub fn dont_use_cow(self, val: bool) -> Self

Use Cow<_,_> for Strings and Bytes

Source

pub fn owned(self, val: bool) -> Self

Generate Owned structs when the proto struct has a lifetime

Source

pub fn nostd(self, val: bool) -> Self

Generate #![no_std] compliant code

Source

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

Source

pub fn gen_info(self, val: bool) -> Self

Generate MessageInfo implementations

Source

pub fn add_deprecated_fields(self, val: bool) -> Self

Add deprecated fields and mark them as #[deprecated]

Source

pub fn build(self) -> Vec<Config>

Build Config from this ConfigBuilder

Trait Implementations§

Source§

impl Debug for ConfigBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConfigBuilder

Source§

fn default() -> ConfigBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.