pub struct Builder { /* private fields */ }
prost
only.Expand description
Service generator builder.
Implementations§
source§impl Builder
impl Builder
sourcepub fn build_client(self, enable: bool) -> Self
pub fn build_client(self, enable: bool) -> Self
Enable or disable gRPC client code generation.
sourcepub fn build_server(self, enable: bool) -> Self
pub fn build_server(self, enable: bool) -> Self
Enable or disable gRPC server code generation.
sourcepub fn build_transport(self, enable: bool) -> Self
pub fn build_transport(self, enable: bool) -> Self
Enable or disable generated clients and servers to have built-in tonic transport features.
When the transport
feature is disabled this does nothing.
sourcepub fn file_descriptor_set_path(self, path: impl AsRef<Path>) -> Self
pub fn file_descriptor_set_path(self, path: impl AsRef<Path>) -> Self
Generate a file containing the encoded prost_types::FileDescriptorSet
for protocol buffers
modules. This is required for implementing gRPC Server Reflection.
sourcepub fn skip_protoc_run(self) -> Self
pub fn skip_protoc_run(self) -> Self
In combination with with file_descriptor_set_path, this can be used to provide a file descriptor set as an input file, rather than having prost-build generate the file by calling protoc.
sourcepub fn out_dir(self, out_dir: impl AsRef<Path>) -> Self
pub fn out_dir(self, out_dir: impl AsRef<Path>) -> Self
Set the output directory to generate code to.
Defaults to the OUT_DIR
environment variable.
sourcepub fn extern_path(
self,
proto_path: impl AsRef<str>,
rust_path: impl AsRef<str>,
) -> Self
pub fn extern_path( self, proto_path: impl AsRef<str>, rust_path: impl AsRef<str>, ) -> Self
Declare externally provided Protobuf package or type.
Passed directly to prost_build::Config.extern_path
.
Note that both the Protobuf path and the rust package paths should both be fully qualified.
i.e. Protobuf paths should start with “.” and rust paths should start with “::”
sourcepub fn field_attribute<P: AsRef<str>, A: AsRef<str>>(
self,
path: P,
attribute: A,
) -> Self
pub fn field_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self
Add additional attribute to matched messages, enums, and one-offs.
Passed directly to prost_build::Config.field_attribute
.
sourcepub fn type_attribute<P: AsRef<str>, A: AsRef<str>>(
self,
path: P,
attribute: A,
) -> Self
pub fn type_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self
Add additional attribute to matched messages, enums, and one-offs.
Passed directly to prost_build::Config.type_attribute
.
sourcepub fn message_attribute<P: AsRef<str>, A: AsRef<str>>(
self,
path: P,
attribute: A,
) -> Self
pub fn message_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self
Add additional attribute to matched messages.
Passed directly to prost_build::Config.message_attribute
.
sourcepub fn enum_attribute<P: AsRef<str>, A: AsRef<str>>(
self,
path: P,
attribute: A,
) -> Self
pub fn enum_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self
Add additional attribute to matched enums.
Passed directly to prost_build::Config.enum_attribute
.
sourcepub fn boxed<P: AsRef<str>>(self, path: P) -> Self
pub fn boxed<P: AsRef<str>>(self, path: P) -> Self
Add additional boxed fields.
Passed directly to prost_build::Config.boxed
.
sourcepub fn btree_map<I, S>(self, paths: I) -> Self
pub fn btree_map<I, S>(self, paths: I) -> Self
Configure the code generator to generate Rust BTreeMap
fields for Protobuf map
type
fields.
Passed directly to prost_build::Config.btree_map
.
Note: previous configured paths for btree_map
will be cleared.
sourcepub fn bytes<I, S>(self, paths: I) -> Self
pub fn bytes<I, S>(self, paths: I) -> Self
Configure the code generator to generate Rust bytes::Bytes
fields for Protobuf bytes
type fields.
Passed directly to prost_build::Config.bytes
.
Note: previous configured paths for bytes
will be cleared.
sourcepub fn server_mod_attribute<P: AsRef<str>, A: AsRef<str>>(
self,
path: P,
attribute: A,
) -> Self
pub fn server_mod_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self
Add additional attribute to matched server mod
s. Matches on the package name.
sourcepub fn server_attribute<P: AsRef<str>, A: AsRef<str>>(
self,
path: P,
attribute: A,
) -> Self
pub fn server_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self
Add additional attribute to matched service servers. Matches on the service name.
sourcepub fn client_mod_attribute<P: AsRef<str>, A: AsRef<str>>(
self,
path: P,
attribute: A,
) -> Self
pub fn client_mod_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self
Add additional attribute to matched client mod
s. Matches on the package name.
sourcepub fn client_attribute<P: AsRef<str>, A: AsRef<str>>(
self,
path: P,
attribute: A,
) -> Self
pub fn client_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self
Add additional attribute to matched service clients. Matches on the service name.
sourcepub fn proto_path(self, proto_path: impl AsRef<str>) -> Self
pub fn proto_path(self, proto_path: impl AsRef<str>) -> Self
Set the path to where tonic will search for the Request/Response proto structs
live relative to the module where you call include_proto!
.
This defaults to super
since tonic will generate code in a module.
sourcepub fn protoc_arg<A: AsRef<str>>(self, arg: A) -> Self
pub fn protoc_arg<A: AsRef<str>>(self, arg: A) -> Self
Configure Prost protoc_args
build arguments.
Note: Enabling --experimental_allow_proto3_optional
requires protobuf >= 3.12.
sourcepub fn disable_comments(self, path: impl AsRef<str>) -> Self
pub fn disable_comments(self, path: impl AsRef<str>) -> Self
Disable service and rpc comments emission.
sourcepub fn use_arc_self(self, enable: bool) -> Self
pub fn use_arc_self(self, enable: bool) -> Self
Emit Arc<Self>
receiver type in server traits instead of &self
.
sourcepub fn disable_package_emission(self) -> Self
pub fn disable_package_emission(self) -> Self
Emits GRPC endpoints with no attached package. Effectively ignores protofile package declaration from grpc context.
This effectively sets prost’s exported package to an empty string.
sourcepub fn compile_well_known_types(self, compile_well_known_types: bool) -> Self
pub fn compile_well_known_types(self, compile_well_known_types: bool) -> Self
Enable or disable directing Prost to compile well-known protobuf types instead
of using the already-compiled versions available in the prost-types
crate.
This defaults to false
.
sourcepub fn include_file(self, path: impl AsRef<Path>) -> Self
pub fn include_file(self, path: impl AsRef<Path>) -> Self
Configures the optional module filename for easy inclusion of all generated Rust files
If set, generates a file (inside the OUT_DIR
or out_dir()
as appropriate) which contains
a set of pub mod XXX
statements combining to load all Rust files generated. This can allow
for a shortcut where multiple related proto files have been compiled together resulting in
a semi-complex set of includes.
sourcepub fn emit_rerun_if_changed(self, enable: bool) -> Self
pub fn emit_rerun_if_changed(self, enable: bool) -> Self
Enable or disable emitting
cargo:rerun-if-changed=PATH
instructions for Cargo.
If set, writes instructions to stdout
for Cargo so that it understands
when to rerun the build script. By default, this setting is enabled if
the CARGO
environment variable is set. The CARGO
environment
variable is set by Cargo for build scripts. Therefore, this setting
should be enabled automatically when run from a build script. However,
the method of detection is not completely reliable since the CARGO
environment variable can have been set by anything else. If writing the
instructions to stdout
is undesirable, you can disable this setting
explicitly.
sourcepub fn generate_default_stubs(self, enable: bool) -> Self
pub fn generate_default_stubs(self, enable: bool) -> Self
Enable or disable directing service generation to providing a default implementation for service methods. When this is false all gRPC methods must be explicitly implemented. When this is true any unimplemented service methods will return ‘unimplemented’ gRPC error code. When this is true all streaming server request RPC types explicitly use tonic::codegen::BoxStream type.
This defaults to false
.
sourcepub fn codec_path(self, codec_path: impl Into<String>) -> Self
pub fn codec_path(self, codec_path: impl Into<String>) -> Self
Override the default codec.
If set, writes {codec_path}::default()
in generated code wherever a codec is created.
This defaults to "tonic::codec::ProstCodec"
sourcepub fn skip_debug(self, path: impl AsRef<str>) -> Self
pub fn skip_debug(self, path: impl AsRef<str>) -> Self
Skips generating impl Debug
for types
sourcepub fn compile(
self,
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
) -> Result<()>
👎Deprecated since 0.12.3: renamed to compile_protos()
pub fn compile( self, protos: &[impl AsRef<Path>], includes: &[impl AsRef<Path>], ) -> Result<()>
compile_protos()
Compile the .proto files and execute code generation.
sourcepub fn compile_with_config(
self,
config: Config,
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
) -> Result<()>
👎Deprecated since 0.12.3: renamed to compile_protos_with_config()
pub fn compile_with_config( self, config: Config, protos: &[impl AsRef<Path>], includes: &[impl AsRef<Path>], ) -> Result<()>
compile_protos_with_config()
Compile the .proto files and execute code generation using a custom
prost_build::Config
. The provided config will be updated with this builder’s config.
sourcepub fn compile_protos(
self,
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
) -> Result<()>
pub fn compile_protos( self, protos: &[impl AsRef<Path>], includes: &[impl AsRef<Path>], ) -> Result<()>
Compile the .proto files and execute code generation.
sourcepub fn compile_protos_with_config(
self,
config: Config,
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
) -> Result<()>
pub fn compile_protos_with_config( self, config: Config, protos: &[impl AsRef<Path>], includes: &[impl AsRef<Path>], ) -> Result<()>
Compile the .proto files and execute code generation using a custom
prost_build::Config
. The provided config will be updated with this builder’s config.
sourcepub fn compile_fds(self, fds: FileDescriptorSet) -> Result<()>
pub fn compile_fds(self, fds: FileDescriptorSet) -> Result<()>
Execute code generation from a file descriptor set.
sourcepub fn compile_fds_with_config(
self,
config: Config,
fds: FileDescriptorSet,
) -> Result<()>
pub fn compile_fds_with_config( self, config: Config, fds: FileDescriptorSet, ) -> Result<()>
Execute code generation from a file descriptor set using a custom prost_build::Config
.
sourcepub fn service_generator(self) -> Box<dyn ServiceGenerator>
pub fn service_generator(self) -> Box<dyn ServiceGenerator>
Turn the builder into a ServiceGenerator
ready to be passed to prost-build
s
Config::service_generator
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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