pub struct Parser { /* private fields */ }
Expand description
Configure and invoke .proto
parser.
Implementations§
source§impl Parser
impl Parser
sourcepub fn new() -> Parser
pub fn new() -> Parser
Create new default configured parser.
Examples found in repository?
examples/file-descriptor-out-compare.rs (line 22)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();
let (path, out_protoc, out_pure) = match args.as_slice() {
// Just invoke protoc.
[path, out_protoc, out_pure] => (path, out_protoc, out_pure),
_ => panic!("wrong args"),
};
for which in [Which::Pure, Which::Protoc] {
let mut parser = Parser::new();
match which {
Which::Protoc => {
parser.protoc();
}
Which::Pure => {
parser.pure();
}
}
parser.input(path);
parser.include(".");
let fds = parser.file_descriptor_set().unwrap();
let fds = text_format::print_to_string_pretty(&fds);
let out = match which {
Which::Protoc => out_protoc,
Which::Pure => out_pure,
};
fs::write(out, fds).unwrap();
}
}
sourcepub fn pure(&mut self) -> &mut Self
pub fn pure(&mut self) -> &mut Self
Use pure rust parser.
Examples found in repository?
examples/file-descriptor-out-compare.rs (line 28)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();
let (path, out_protoc, out_pure) = match args.as_slice() {
// Just invoke protoc.
[path, out_protoc, out_pure] => (path, out_protoc, out_pure),
_ => panic!("wrong args"),
};
for which in [Which::Pure, Which::Protoc] {
let mut parser = Parser::new();
match which {
Which::Protoc => {
parser.protoc();
}
Which::Pure => {
parser.pure();
}
}
parser.input(path);
parser.include(".");
let fds = parser.file_descriptor_set().unwrap();
let fds = text_format::print_to_string_pretty(&fds);
let out = match which {
Which::Protoc => out_protoc,
Which::Pure => out_pure,
};
fs::write(out, fds).unwrap();
}
}
sourcepub fn protoc(&mut self) -> &mut Self
pub fn protoc(&mut self) -> &mut Self
Use protoc
for parsing.
Examples found in repository?
examples/file-descriptor-out-compare.rs (line 25)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();
let (path, out_protoc, out_pure) = match args.as_slice() {
// Just invoke protoc.
[path, out_protoc, out_pure] => (path, out_protoc, out_pure),
_ => panic!("wrong args"),
};
for which in [Which::Pure, Which::Protoc] {
let mut parser = Parser::new();
match which {
Which::Protoc => {
parser.protoc();
}
Which::Pure => {
parser.pure();
}
}
parser.input(path);
parser.include(".");
let fds = parser.file_descriptor_set().unwrap();
let fds = text_format::print_to_string_pretty(&fds);
let out = match which {
Which::Protoc => out_protoc,
Which::Pure => out_pure,
};
fs::write(out, fds).unwrap();
}
}
sourcepub fn include(&mut self, include: impl AsRef<Path>) -> &mut Self
pub fn include(&mut self, include: impl AsRef<Path>) -> &mut Self
Add an include directory.
Examples found in repository?
examples/file-descriptor-out-compare.rs (line 33)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();
let (path, out_protoc, out_pure) = match args.as_slice() {
// Just invoke protoc.
[path, out_protoc, out_pure] => (path, out_protoc, out_pure),
_ => panic!("wrong args"),
};
for which in [Which::Pure, Which::Protoc] {
let mut parser = Parser::new();
match which {
Which::Protoc => {
parser.protoc();
}
Which::Pure => {
parser.pure();
}
}
parser.input(path);
parser.include(".");
let fds = parser.file_descriptor_set().unwrap();
let fds = text_format::print_to_string_pretty(&fds);
let out = match which {
Which::Protoc => out_protoc,
Which::Pure => out_pure,
};
fs::write(out, fds).unwrap();
}
}
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
Examples found in repository?
examples/file-descriptor-out-compare.rs (line 32)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();
let (path, out_protoc, out_pure) = match args.as_slice() {
// Just invoke protoc.
[path, out_protoc, out_pure] => (path, out_protoc, out_pure),
_ => panic!("wrong args"),
};
for which in [Which::Pure, Which::Protoc] {
let mut parser = Parser::new();
match which {
Which::Protoc => {
parser.protoc();
}
Which::Pure => {
parser.pure();
}
}
parser.input(path);
parser.include(".");
let fds = parser.file_descriptor_set().unwrap();
let fds = text_format::print_to_string_pretty(&fds);
let out = match which {
Which::Protoc => out_protoc,
Which::Pure => out_pure,
};
fs::write(out, fds).unwrap();
}
}
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
path used for parsing.
This is ignored if pure rust parser is used.
sourcepub fn protoc_extra_args(
&mut self,
args: impl IntoIterator<Item = impl AsRef<OsStr>>,
) -> &mut Self
pub fn protoc_extra_args( &mut self, args: impl IntoIterator<Item = impl AsRef<OsStr>>, ) -> &mut Self
Extra arguments to pass to protoc
command (like experimental options).
This is ignored if pure rust parser is used.
sourcepub fn capture_stderr(&mut self) -> &mut Self
pub fn capture_stderr(&mut self) -> &mut Self
Capture stderr and return it in error.
This option applies only to protoc
parser.
By default protoc
stderr is inherited from this process stderr.
sourcepub fn parse_and_typecheck(&self) -> Result<ParsedAndTypechecked>
pub fn parse_and_typecheck(&self) -> Result<ParsedAndTypechecked>
Parse .proto
files and typecheck them using pure Rust parser of protoc
command.
sourcepub fn file_descriptor_set(&self) -> Result<FileDescriptorSet>
pub fn file_descriptor_set(&self) -> Result<FileDescriptorSet>
Parse and convert result to FileDescriptorSet
.
Examples found in repository?
examples/file-descriptor-out-compare.rs (line 34)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();
let (path, out_protoc, out_pure) = match args.as_slice() {
// Just invoke protoc.
[path, out_protoc, out_pure] => (path, out_protoc, out_pure),
_ => panic!("wrong args"),
};
for which in [Which::Pure, Which::Protoc] {
let mut parser = Parser::new();
match which {
Which::Protoc => {
parser.protoc();
}
Which::Pure => {
parser.pure();
}
}
parser.input(path);
parser.include(".");
let fds = parser.file_descriptor_set().unwrap();
let fds = text_format::print_to_string_pretty(&fds);
let out = match which {
Which::Protoc => out_protoc,
Which::Pure => out_pure,
};
fs::write(out, fds).unwrap();
}
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Parser
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnwindSafe for Parser
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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