Skip to content

Commit

Permalink
reflection: deprecate non-specific build() method
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Aug 23, 2024
1 parent 697b2e7 commit c656001
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/src/reflection/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl proto::greeter_server::Greeter for MyGreeter {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(proto::FILE_DESCRIPTOR_SET)
.build()
.build_v1()
.unwrap();

let addr = "[::1]:50052".parse().unwrap();
Expand Down
10 changes: 9 additions & 1 deletion tonic-reflection/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ impl<'b> Builder<'b> {
}

/// Build a v1 gRPC Reflection Service to be served via Tonic.
pub fn build(mut self) -> Result<v1::ServerReflectionServer<impl v1::ServerReflection>, Error> {
#[deprecated(since = "0.12.2", note = "use `build_v1()` instead")]
pub fn build(self) -> Result<v1::ServerReflectionServer<impl v1::ServerReflection>, Error> {
self.build_v1()
}

/// Build a v1 gRPC Reflection Service to be served via Tonic.
pub fn build_v1(
mut self,
) -> Result<v1::ServerReflectionServer<impl v1::ServerReflection>, Error> {
if self.include_reflection_service {
self = self.register_encoded_file_descriptor_set(crate::pb::v1::FILE_DESCRIPTOR_SET);
}
Expand Down
2 changes: 1 addition & 1 deletion tonic-reflection/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async fn make_test_reflection_request(request: ServerReflectionRequest) -> Messa
let jh = tokio::spawn(async move {
let service = Builder::configure()
.register_encoded_file_descriptor_set(FILE_DESCRIPTOR_SET)
.build()
.build_v1()
.unwrap();

Server::builder()
Expand Down
2 changes: 1 addition & 1 deletion tonic-reflection/tests/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn make_v1_request(
let listener = tokio::net::TcpListener::bind(addr).await.expect("bind");
let local_addr = format!("http://{}", listener.local_addr().expect("local address"));
let jh = tokio::spawn(async move {
let service = Builder::configure().build().unwrap();
let service = Builder::configure().build_v1().unwrap();

Server::builder()
.add_service(service)
Expand Down

0 comments on commit c656001

Please sign in to comment.