Skip to content

Commit 3ecd726

Browse files
committed
Default impl
1 parent 49a738d commit 3ecd726

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

crates/twirp-build/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ impl prost_build::ServiceGenerator for ServiceGenerator {
172172
let request_path = format!("{}/{}", service.fqn, m.proto_name);
173173

174174
client_trait_methods.push(quote! {
175-
async fn #name(&self, req: #input_type) -> Result<#output_type, twirp::ClientError>;
175+
async fn #name(&self, req: #input_type) -> Result<#output_type, twirp::ClientError> {
176+
self.#name_request(req)?.send().await
177+
}
176178
});
177179
client_trait_methods.push(quote! {
178180
fn #name_request(&self, req: #input_type) -> Result<twirp::RequestBuilder<#input_type, #output_type>, twirp::ClientError>;
@@ -183,11 +185,6 @@ impl prost_build::ServiceGenerator for ServiceGenerator {
183185
self.request(#request_path, req)
184186
}
185187
});
186-
client_methods.push(quote! {
187-
async fn #name(&self, req: #input_type) -> Result<#output_type, twirp::ClientError> {
188-
self.#name_request(req)?.send().await
189-
}
190-
});
191188
}
192189
let client_trait = quote! {
193190
#[twirp::async_trait::async_trait]

example/src/bin/client.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl HaberdasherApiClient for MockHaberdasherApiClient {
9393
) -> Result<twirp::RequestBuilder<MakeHatRequest, MakeHatResponse>, twirp::ClientError> {
9494
todo!()
9595
}
96+
// implementing this one is optional
9697
async fn make_hat(&self, _req: MakeHatRequest) -> Result<MakeHatResponse, twirp::ClientError> {
9798
todo!()
9899
}
@@ -104,6 +105,7 @@ impl HaberdasherApiClient for MockHaberdasherApiClient {
104105
{
105106
todo!()
106107
}
108+
// implementing this one is optional
107109
async fn get_status(
108110
&self,
109111
_req: GetStatusRequest,

0 commit comments

Comments
 (0)