Skip to content

Commit

Permalink
Cleanup: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
missingdays committed Nov 29, 2024
1 parent 04dc1b7 commit 8c00c05
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
55 changes: 42 additions & 13 deletions volo-build/src/grpc_backend.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::io::Write;
use std::path::Path;
use crate::util::{get_base_dir, write_file, write_item};
use itertools::Itertools;
use pilota_build::middle::context::Mode;
use pilota_build::{
db::RirDatabase,
rir,
rir::Method,
tags::protobuf::{ClientStreaming, ServerStreaming},
CodegenBackend, Context, DefId, IdentName, Symbol,
};
use pilota_build::middle::context::Mode;
use std::io::Write;
use std::path::Path;
use volo::FastStr;
use crate::util::{get_base_dir, write_file, write_item};

pub struct MkGrpcBackend;

Expand Down Expand Up @@ -440,7 +440,7 @@ impl CodegenBackend for VoloGrpcBackend {
}}"
);

let req_enum_send_impl = format! {
let req_enum_send_impl = format! {
r#"
pub enum {req_enum_name_send} {{
{req_enum_send_variants}
Expand Down Expand Up @@ -604,13 +604,43 @@ impl CodegenBackend for VoloGrpcBackend {

if self.cx().split {
let mut mod_rs_stream = String::new();
write_item(&mut mod_rs_stream, base_dir, format!("enum_{}.rs", req_enum_name_send), req_enum_send_impl);
write_item(&mut mod_rs_stream, base_dir, format!("enum_{}.rs", req_enum_name_recv), req_enum_recv_impl);
write_item(&mut mod_rs_stream, base_dir, format!("enum_{}.rs", resp_enum_name_send), resp_enum_send_impl);
write_item(&mut mod_rs_stream, base_dir, format!("enum_{}.rs", resp_enum_name_recv), resp_enum_recv_impl);
write_item(
&mut mod_rs_stream,
base_dir,
format!("enum_{}.rs", req_enum_name_send),
req_enum_send_impl,
);
write_item(
&mut mod_rs_stream,
base_dir,
format!("enum_{}.rs", req_enum_name_recv),
req_enum_recv_impl,
);
write_item(
&mut mod_rs_stream,
base_dir,
format!("enum_{}.rs", resp_enum_name_send),
resp_enum_send_impl,
);
write_item(
&mut mod_rs_stream,
base_dir,
format!("enum_{}.rs", resp_enum_name_recv),
resp_enum_recv_impl,
);

write_item(&mut mod_rs_stream, base_dir, format!("client_{}.rs", client_name), client_impl);
write_item(&mut mod_rs_stream, base_dir, format!("server_{}.rs", server_name), server_impl);
write_item(
&mut mod_rs_stream,
base_dir,
format!("client_{}.rs", client_name),
client_impl,
);
write_item(
&mut mod_rs_stream,
base_dir,
format!("server_{}.rs", server_name),
server_impl,
);

let mod_rs_file_path = base_dir.join("mod.rs");
write_file(&mod_rs_file_path, mod_rs_stream);
Expand All @@ -619,7 +649,7 @@ impl CodegenBackend for VoloGrpcBackend {
"include!(\"{}/mod.rs\");",
base_dir.file_name().unwrap().to_str().unwrap()
)
.as_str(),
.as_str(),
);
} else {
stream.push_str(&format! {
Expand All @@ -635,7 +665,6 @@ impl CodegenBackend for VoloGrpcBackend {
}
}


fn codegen_service_method(&self, _service_def_id: DefId, method: &rir::Method) -> String {
let client_streaming = self
.cx()
Expand Down
2 changes: 1 addition & 1 deletion volo-build/src/thrift_backend.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{io::Write, path::Path};

use crate::util::{get_base_dir, write_file, write_item};
use itertools::Itertools;
use pilota_build::{
codegen::thrift::DecodeHelper,
Expand All @@ -11,7 +12,6 @@ use pilota_build::{
};
use quote::format_ident;
use volo::FastStr;
use crate::util::{get_base_dir, write_file, write_item};

#[derive(Clone)]
pub struct VoloThriftBackend {
Expand Down
2 changes: 1 addition & 1 deletion volo-build/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,4 +912,4 @@ pub(crate) fn get_base_dir(mode: &Mode, def_id: Option<&usize>, path: &[Symbol])
};
let base_dir = Path::new(&base_dir);
base_dir.to_path_buf()
}
}

0 comments on commit 8c00c05

Please sign in to comment.