Skip to content

Commit 9cffd32

Browse files
committed
compiler: write_async_server_create: Fix no methods mut issue
Got follow build issue with a service that doesn't have normal methods and just has stream methods: error: variable does not need to be mutable --> /home/t4/teawater/coco/kata-containers/src/libs/protocols/src/attestation_agent_ttrpc.rs:60:9 | 60 | let mut methods = HashMap::new(); | ----^^^^^^^ | | | help: remove this `mut` | = note: `-D unused-mut` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_mut)]` The reason is the code that generate from proto file is: let mut methods = HashMap::new(); let mut streams = HashMap::new(); streams.insert("ContainerEventsStream".to_string(), Arc::new(ContainerEventsStreamMethod{service: service.clone()}) as Arc<dyn ::ttrpc::r#async::StreamHandler + Send + Sync>); ret.insert("grpc.AttestationAgent".to_string(), ::ttrpc::r#async::Service{ methods, streams }); ret This commit update function write_async_server_create to handle this issue. Fixes: #273 Signed-off-by: Hui Zhu <teawater@antgroup.com>
1 parent cfe37a2 commit 9cffd32

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

compiler/src/codegen.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ impl<'a> ServiceGen<'a> {
486486
.any(|method| !matches!(method.method_type().0, MethodType::Unary))
487487
}
488488

489+
fn has_normal_method(&self) -> bool {
490+
self.methods
491+
.iter()
492+
.any(|method| matches!(method.method_type().0, MethodType::Unary))
493+
}
494+
489495
fn write_client(&self, w: &mut CodeWriter) {
490496
if async_on(self.customize, "client") {
491497
self.write_async_client(w)
@@ -588,9 +594,14 @@ impl<'a> ServiceGen<'a> {
588594
);
589595

590596
let has_stream_method = self.has_stream_method();
597+
let has_normal_method = self.has_normal_method();
591598
w.pub_fn(&s, |w| {
592599
w.write_line("let mut ret = HashMap::new();");
593-
w.write_line("let mut methods = HashMap::new();");
600+
if has_normal_method {
601+
w.write_line("let mut methods = HashMap::new();");
602+
} else {
603+
w.write_line("let methods = HashMap::new();");
604+
}
594605
if has_stream_method {
595606
w.write_line("let mut streams = HashMap::new();");
596607
} else {

0 commit comments

Comments
 (0)