pub struct Codegen { /* private fields */ }
Expand description

Entry point for .proto to .rs code generation.

This is similar to protoc --rust_out....

Implementations§

source§

impl Codegen

source

pub fn new() -> Self

Create new codegen object.

Uses protoc from $PATH by default.

Can be switched to pure rust parser using pure function.

source

pub fn pure(&mut self) -> &mut Self

Switch to pure Rust parser of .proto files.

source

pub fn protoc(&mut self) -> &mut Self

Switch to protoc parser of .proto files.

source

pub fn out_dir(&mut self, out_dir: impl AsRef<Path>) -> &mut Self

Output directory for generated code.

When invoking from build.rs, consider using cargo_out_dir instead.

source

pub fn cargo_out_dir(&mut self, rel: &str) -> &mut Self

Set output directory relative to Cargo output dir.

With this option, output directory is erased and recreated during invocation.

source

pub fn include(&mut self, include: impl AsRef<Path>) -> &mut Self

Add an include directory.

source

pub fn includes( &mut self, includes: impl IntoIterator<Item = impl AsRef<Path>> ) -> &mut Self

Add include directories.

source

pub fn input(&mut self, input: impl AsRef<Path>) -> &mut Self

Append a .proto file path to compile

source

pub fn inputs( &mut self, inputs: impl IntoIterator<Item = impl AsRef<Path>> ) -> &mut Self

Append multiple .proto file paths to compile

source

pub fn protoc_path(&mut self, protoc: &Path) -> &mut Self

Specify protoc command path to be used when invoking code generation.

§Examples

use protobuf_codegen::Codegen;

Codegen::new()
    .protoc()
    .protoc_path(&protoc_bin_vendored::protoc_bin_path().unwrap())
    // ...
    .run()
    .unwrap();

This option is ignored when pure Rust parser is used.

source

pub fn capture_stderr(&mut self) -> &mut Self

Capture stderr to error when running protoc.

source

pub fn protoc_extra_arg(&mut self, arg: impl Into<OsString>) -> &mut Self

Extra command line flags for protoc invocation.

For example, --experimental_allow_proto3_optional option.

This option is ignored when pure Rust parser is used.

source

pub fn customize(&mut self, customize: Customize) -> &mut Self

Set options to customize code generation

source

pub fn customize_callback( &mut self, callback: impl CustomizeCallback ) -> &mut Self

Callback for dynamic per-element customization.

source

pub fn run(&self) -> Result<()>

Invoke the code generation.

This is roughly equivalent to protoc --rust_out=... but without requiring protoc-gen-rust command in $PATH.

This function uses pure Rust parser or protoc parser depending on how this object was configured.

source

pub fn run_from_script(&self)

Similar to run, but prints the message to stderr and exits the process on error.

Trait Implementations§

source§

impl Debug for Codegen

source§

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

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

impl Default for Codegen

source§

fn default() -> Codegen

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Codegen

§

impl !Send for Codegen

§

impl !Sync for Codegen

§

impl Unpin for Codegen

§

impl !UnwindSafe for Codegen

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>,

§

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>,

§

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.