tonic_build::manual

Struct MethodBuilder

source
pub struct MethodBuilder { /* private fields */ }
Expand description

Method builder.

This builder can be used to manually define gRPC method, which can be added to a gRPC service, in rust code without the use of a .proto file.

§Example

let say_hello_method = Method::builder()
    .name("say_hello")
    .route_name("SayHello")
    // Provide the path to the Request type
    .input_type("crate::common::HelloRequest")
    // Provide the path to the Response type
    .output_type("crate::common::HelloResponse")
    // Provide the path to the Codec to use
    .codec_path("crate::common::JsonCodec")
    .build();

Implementations§

source§

impl MethodBuilder

source

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

Set the name for this Method.

This value will be used for generating the client functions for calling this Method.

Generally this is formatted in snake_case.

source

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

Set the route_name for this Method.

This value will be used as part of the route for calling this method. Routes have the form: /<package_name>.<service_name>/<method_route_name>

Generally this is formatted in PascalCase.

source

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

Add a comment string that should be included as a doc comment for this Method.

source

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

Set the path to the Rust type that should be use for the Request type of this method.

source

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

Set the path to the Rust type that should be use for the Response type of this method.

source

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

Set the path to the Rust type that should be used as the Codec for this method.

Currently the codegen assumes that this type implements Default.

source

pub fn client_streaming(self) -> Self

Sets if the Method request from the client is streamed.

source

pub fn server_streaming(self) -> Self

Sets if the Method response from the server is streamed.

source

pub fn build(self) -> Method

Build a Method

Panics if name, route_name, input_type, output_type, or codec_path weren’t set.

Trait Implementations§

source§

impl Debug for MethodBuilder

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for MethodBuilder

source§

fn default() -> MethodBuilder

Returns the “default value” for a type. 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> 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, 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.