Skip to content

Commit e5264e0

Browse files
authored
Merge pull request #282 from teawater/streams_warn
compiler: write_async_server_create: Fix no methods mut issue
2 parents cfe37a2 + fe0ea53 commit e5264e0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

compiler/src/codegen.rs

Lines changed: 18 additions & 2 deletions
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)
@@ -568,8 +574,13 @@ impl<'a> ServiceGen<'a> {
568574
method_handler_name,
569575
);
570576

577+
let has_normal_method = self.has_normal_method();
571578
w.pub_fn(&s, |w| {
572-
w.write_line("let mut methods = HashMap::new();");
579+
if has_normal_method {
580+
w.write_line("let mut methods = HashMap::new();");
581+
} else {
582+
w.write_line("let methods = HashMap::new();");
583+
}
573584
for method in &self.methods[0..self.methods.len()] {
574585
w.write_line("");
575586
method.write_bind(w);
@@ -588,9 +599,14 @@ impl<'a> ServiceGen<'a> {
588599
);
589600

590601
let has_stream_method = self.has_stream_method();
602+
let has_normal_method = self.has_normal_method();
591603
w.pub_fn(&s, |w| {
592604
w.write_line("let mut ret = HashMap::new();");
593-
w.write_line("let mut methods = HashMap::new();");
605+
if has_normal_method {
606+
w.write_line("let mut methods = HashMap::new();");
607+
} else {
608+
w.write_line("let methods = HashMap::new();");
609+
}
594610
if has_stream_method {
595611
w.write_line("let mut streams = HashMap::new();");
596612
} else {

0 commit comments

Comments
 (0)