Struct Builder

Source
pub struct Builder { /* private fields */ }
Expand description

Service generator builder.

Implementations§

Source§

impl Builder

Source

pub fn build_client(self, enable: bool) -> Self

Enable or disable client code generation.

Source

pub fn build_server(self, enable: bool) -> Self

Enable or disable server code generation.

Source

pub fn build_scale_ext(self, enable: bool) -> Self

Enable or disable scale codec extensions generation.

Source

pub fn format(self, run: bool) -> Self

Enable the output to be formated by rustfmt.

Source

pub fn mod_prefix(self, prefix: impl Into<String>) -> Self

Module prefix of the generated code.

Source

pub fn type_prefix(self, prefix: impl Into<String>) -> Self

Type prefix of the scale codec anotation in the proto file.

Source

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.

Source

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 “::”

Source

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.

Source

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.

Source

pub fn server_mod_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self

Add additional attribute to matched server mods. Matches on the package name.

Source

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.

Source

pub fn client_mod_attribute<P: AsRef<str>, A: AsRef<str>>( self, path: P, attribute: A, ) -> Self

Add additional attribute to matched client mods. Matches on the package name.

Source

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.

Source

pub fn proto_path(self, proto_path: impl AsRef<str>) -> Self

Set the path to where to search for the Request/Response proto structs live relative to the module where you call include_proto!.

This defaults to super since we will generate code in a module.

Source

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.

Source

pub fn disable_package_emission(self) -> Self

Emits RPC endpoints with no attached package. Effectively ignores protofile package declaration from rpc context.

This effectively sets prost’s exported package to an empty string.

Source

pub fn disable_service_name_emission(self) -> Self

Disable emitting service name in rpc endpoints.

Source

pub fn keep_service_name(self, name: impl Into<String>) -> Self

Keep the service name in rpc endpoints.

Source

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.

Source

pub fn file_descriptor_set_path(self, path: impl Into<PathBuf>) -> Self

When set, the FileDescriptorSet generated by protoc is written to the provided filesystem path.

This option can be used in conjunction with the include_bytes! macro and the types in the prost-types crate for implementing reflection capabilities, among other things.

Source

pub fn compile( self, protos: &[impl AsRef<Path>], includes: &[impl AsRef<Path>], ) -> Result<()>

Compile the .proto files and execute code generation.

Source

pub fn compile_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.

Source

pub fn enable_serde_extension(self) -> Self

Enable serde serialization/deserialization for all generated types. This adds the necessary derives and attributes for serde compatibility.

Source

pub fn compile_dir(self, proto_dir: impl AsRef<Path>) -> Result<()>

Compile all .proto files in the specified directory. The include directory will be the same as the proto directory.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.