pub struct Codegen { /* private fields */ }Expand description
Entry point for .proto to .rs code generation.
This is similar to protoc --rs_out....
Implementations§
Source§impl Codegen
impl Codegen
Sourcepub fn new() -> Self
pub fn new() -> Self
Create new codegen object.
Uses protoc from $PATH by default.
Can be switched to pure rust parser using pure function.
Sourcepub fn out_dir(&mut self, out_dir: impl AsRef<Path>) -> &mut Self
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.
Sourcepub fn cargo_out_dir(&mut self, rel: &str) -> &mut Self
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.
Sourcepub fn includes(
&mut self,
includes: impl IntoIterator<Item = impl AsRef<Path>>,
) -> &mut Self
pub fn includes( &mut self, includes: impl IntoIterator<Item = impl AsRef<Path>>, ) -> &mut Self
Add include directories.
Sourcepub fn input(&mut self, input: impl AsRef<Path>) -> &mut Self
pub fn input(&mut self, input: impl AsRef<Path>) -> &mut Self
Append a .proto file path to compile
Sourcepub fn inputs(
&mut self,
inputs: impl IntoIterator<Item = impl AsRef<Path>>,
) -> &mut Self
pub fn inputs( &mut self, inputs: impl IntoIterator<Item = impl AsRef<Path>>, ) -> &mut Self
Append multiple .proto file paths to compile
Sourcepub fn protoc_path(&mut self, protoc: &Path) -> &mut Self
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.
Sourcepub fn capture_stderr(&mut self) -> &mut Self
pub fn capture_stderr(&mut self) -> &mut Self
Capture stderr to error when running protoc.
Sourcepub fn protoc_extra_arg(&mut self, arg: impl Into<OsString>) -> &mut Self
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.
Sourcepub fn customize(&mut self, customize: Customize) -> &mut Self
pub fn customize(&mut self, customize: Customize) -> &mut Self
Set options to customize code generation
Sourcepub fn customize_callback(
&mut self,
callback: impl CustomizeCallback,
) -> &mut Self
pub fn customize_callback( &mut self, callback: impl CustomizeCallback, ) -> &mut Self
Callback for dynamic per-element customization.
Sourcepub fn run(&self) -> Result<()>
pub fn run(&self) -> Result<()>
Invoke the code generation.
This is roughly equivalent to protoc --rs_out=... but
without requiring protoc-gen-rs command in $PATH.
This function uses pure Rust parser or protoc parser depending on
how this object was configured.
Sourcepub fn run_from_script(&self)
pub fn run_from_script(&self)
Similar to run, but prints the message to stderr and exits the process on error.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Codegen
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more