Struct TwirpBuilder

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

Builds protobuf bindings for Twirp.

Client and server are not enabled by defaults and must be enabled with the with_client and with_server methods.

Implementations§

Source§

impl TwirpBuilder

Source

pub fn new() -> Self

Builder with the default prost Config.

Source

pub fn from_prost(config: Config) -> Self

Builder with a custom prost Config.

Source

pub fn with_client(self) -> Self

Generates code for the Twirp client.

Source

pub fn with_server(self) -> Self

Generates code for the Twirp server.

Source

pub fn with_grpc(self) -> Self

Generates code for gRPC alongside Twirp.

Source

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

Adds an extra parameter to generated server methods that implements axum::FromRequestParts.

For example

message Service {
    rpc Test(TestRequest) returns (TestResponse) {}
}

Compiled with option .with_axum_request_extractor("headers", "::axum::http::HeaderMap") will generate the following code allowing to extract the request headers:

trait Service {
    async fn test(request: TestRequest, headers: ::axum::http::HeaderMap) -> Result<TestResponse, TwirpError>;
}

Note that the parameter type must implement axum::FromRequestParts.

Source

pub fn with_type_name_domain(self, domain: impl Into<String>) -> Self

Customizes the type name domain.

By default, ‘type.googleapis.com’ is used.

Source

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

Do compile the protos.

Trait Implementations§

Source§

impl Default for TwirpBuilder

Source§

fn default() -> TwirpBuilder

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.