Skip to content

Commit

Permalink
feat(codgen): Add default implementations for the generated serve… (#27)
Browse files Browse the repository at this point in the history
* Rename servce -> server

* Add default impl for server trait
  • Loading branch information
LucioFranco authored Oct 2, 2019
1 parent 2670b34 commit 4559613
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tonic-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use std::{
};

mod client;
mod service;
mod server;

/// Service generator builder.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -207,7 +207,7 @@ impl prost_build::ServiceGenerator for ServiceGenerator {
let path = "super";

if self.builder.build_server {
let server = service::generate(&service, path);
let server = server::generate(&service, path);
self.servers.extend(server);
}

Expand Down
16 changes: 12 additions & 4 deletions tonic-build/src/service.rs → tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ fn generate_trait_methods(service: &Service, proto_path: &str) -> TokenStream {
quote! {
#method_doc
async fn #name(&self, request: tonic::Request<#req_message>)
-> Result<tonic::Response<#res_message>, tonic::Status>;
-> Result<tonic::Response<#res_message>, tonic::Status> {
Err(tonic::Status::unimplemented("Not yet implemented"))
}
}
}
(true, false) => {
quote! {
#method_doc
async fn #name(&self, request: tonic::Request<tonic::Streaming<#req_message>>)
-> Result<tonic::Response<#res_message>, tonic::Status>;
-> Result<tonic::Response<#res_message>, tonic::Status> {
Err(tonic::Status::unimplemented("Not yet implemented"))
}
}
}
(false, true) => {
Expand All @@ -147,7 +151,9 @@ fn generate_trait_methods(service: &Service, proto_path: &str) -> TokenStream {

#method_doc
async fn #name(&self, request: tonic::Request<#req_message>)
-> Result<tonic::Response<Self::#stream>, tonic::Status>;
-> Result<tonic::Response<Self::#stream>, tonic::Status> {
Err(tonic::Status::unimplemented("Not yet implemented"))
}
}
}
(true, true) => {
Expand All @@ -163,7 +169,9 @@ fn generate_trait_methods(service: &Service, proto_path: &str) -> TokenStream {

#method_doc
async fn #name(&self, request: tonic::Request<tonic::Streaming<#req_message>>)
-> Result<tonic::Response<Self::#stream>, tonic::Status>;
-> Result<tonic::Response<Self::#stream>, tonic::Status> {
Err(tonic::Status::unimplemented("Not yet implemented"))
}
}
}
};
Expand Down

0 comments on commit 4559613

Please sign in to comment.