pub struct Compiler { /* private fields */ }
Expand description
Options for compiling protobuf files.
Examples
fs::write("bar.proto", "
message Bar { }
").unwrap();
let file_descriptor_set = Compiler::new(["."])?
.include_imports(true)
.include_source_info(false)
.open_file("bar.proto")?
.file_descriptor_set();
assert_eq!(file_descriptor_set.file[0].message_type[0].name(), "Bar");
Implementations§
source§impl Compiler
impl Compiler
sourcepub fn with_file_resolver<R>(resolver: R) -> Selfwhere
R: FileResolver + 'static,
pub fn with_file_resolver<R>(resolver: R) -> Selfwhere
R: FileResolver + 'static,
Creates a new Compiler
with a custom FileResolver
for looking up imported files.
sourcepub fn include_source_info(&mut self, yes: bool) -> &mut Self
pub fn include_source_info(&mut self, yes: bool) -> &mut Self
Sets whether the output FileDescriptorSet
should include source info.
If set, the file descriptors returned by file_descriptor_set
will have
the FileDescriptorProto::source_code_info
field
populated with source locations and comments.
sourcepub fn include_imports(&mut self, yes: bool) -> &mut Self
pub fn include_imports(&mut self, yes: bool) -> &mut Self
Sets whether the output FileDescriptorSet
should include imported files.
By default, only files explicitly added with open_file
are returned by file_descriptor_set
.
If this option is set, imported files are included too.
sourcepub fn open_file(&mut self, path: impl AsRef<Path>) -> Result<&mut Self, Error>
pub fn open_file(&mut self, path: impl AsRef<Path>) -> Result<&mut Self, Error>
Compiles the file at the given path, and adds it to this Compiler
instance.
If the path is absolute, or relative to the current directory, it must reside under one of the
include paths. Otherwise, it is looked up relative to the given include paths in the same way as
import
statements.
sourcepub fn open_files(
&mut self,
paths: impl IntoIterator<Item = impl AsRef<Path>>
) -> Result<&mut Self, Error>
pub fn open_files( &mut self, paths: impl IntoIterator<Item = impl AsRef<Path>> ) -> Result<&mut Self, Error>
Compiles the given files, and adds them to this Compiler
instance.
See open_file()
.
sourcepub fn file_descriptor_set(&self) -> FileDescriptorSet
pub fn file_descriptor_set(&self) -> FileDescriptorSet
Converts all added files into an instance of FileDescriptorSet
.
Files are sorted topologically, with dependency files ordered before the files that import them.
sourcepub fn encode_file_descriptor_set(&self) -> Vec<u8>
pub fn encode_file_descriptor_set(&self) -> Vec<u8>
Converts all added files into an instance of FileDescriptorSet
and encodes it.
This is equivalent to file_descriptor_set()?.encode_to_vec()
, with the exception that extension
options are included.
sourcepub fn descriptor_pool(&self) -> DescriptorPool
pub fn descriptor_pool(&self) -> DescriptorPool
Gets a copy of the DescriptorPool
containing all referenced files.
sourcepub fn files(&self) -> impl ExactSizeIterator<Item = &FileMetadata>
pub fn files(&self) -> impl ExactSizeIterator<Item = &FileMetadata>
Gets a reference to all imported source files.
The files will appear in topological order, so each file appears before any file that imports it.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Compiler
impl !Send for Compiler
impl !Sync for Compiler
impl Unpin for Compiler
impl !UnwindSafe for Compiler
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
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more