Struct protobuf_codegen::Codegen
source · 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
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 --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.
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.