Skip to content

Commit bfa8710

Browse files
committed
codegen: Fix issues reported by cargo clippy
Fix all issues reported by cargo clippy to make ci testing pass. Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
1 parent c22744f commit bfa8710

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export PROTOC=${HOME}/protoc/bin/protoc
2+
13
all: debug test
24

35
#

codegen/src/codegen.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ where
4848
let fd_set = FileDescriptorSet::decode(&buffer as &[u8]).context("Decode fd_set")?;
4949

5050
for fd in fd_set.file.iter() {
51-
let rs_path =
52-
PathBuf::from(self.out_dir.as_ref()).join(&format!("{}.rs", fd.package()));
51+
let rs_path = PathBuf::from(self.out_dir.as_ref()).join(format!("{}.rs", fd.package()));
5352
let mut f = match File::open(&rs_path) {
5453
Ok(f) => f,
5554
_ => continue,
@@ -169,20 +168,14 @@ where
169168
None => return Err(anyhow!("The includes are required.")),
170169
};
171170

172-
let serde = match self.serde {
173-
Some(serde) => serde,
174-
None => false,
175-
};
171+
let serde = self.serde.unwrap_or(false);
176172

177173
let async_mode = match self.async_mode {
178174
Some(mode) => mode,
179175
None => AsyncMode::None,
180176
};
181177

182-
let generate_service = match self.generate_service {
183-
Some(gen) => gen,
184-
None => false,
185-
};
178+
let generate_service = self.generate_service.unwrap_or(false);
186179

187180
Ok(Codegen {
188181
out_dir,

codegen/src/svcgen.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl TtrpcServiceGenerator {
253253
quote!( let streams = HashMap::new(); )
254254
};
255255
let method_inserts: Vec<_> = service.methods.iter().map(|method| {
256-
let key = format!("{}", method.proto_name);
256+
let key = method.proto_name.to_string();
257257
let mm = format_ident!("{}Method", to_camel_case(&method.proto_name));
258258
match MethodType::from_method(method) {
259259
MethodType::Unary => {
@@ -349,7 +349,7 @@ impl TtrpcServiceGenerator {
349349
let input = type_token(&method.input_type);
350350
let output = type_token(&method.output_type);
351351
let server_str = format!("{}.{}", service.package, service.name);
352-
let method_str = format!("{}", method.proto_name);
352+
let method_str = method.proto_name.to_string();
353353

354354
match MethodType::from_method(method) {
355355
MethodType::Unary => {
@@ -373,7 +373,7 @@ impl TtrpcServiceGenerator {
373373
let input = type_token(&method.input_type);
374374
let output = type_token(&method.output_type);
375375
let server_str = format!("{}.{}", service.package, service.name);
376-
let method_str = format!("{}", method.proto_name);
376+
let method_str = method.proto_name.to_string();
377377

378378
let (mut arg_tokens, ret_token, body_token) = match MethodType::from_method(method) {
379379
MethodType::Unary => (
@@ -497,7 +497,7 @@ enum Side {
497497
}
498498

499499
fn async_on(mode: AsyncMode, side: Side) -> bool {
500-
return mode == AsyncMode::All
500+
mode == AsyncMode::All
501501
|| (side == Side::Server && mode == AsyncMode::Server)
502-
|| (side == Side::Client && mode == AsyncMode::Client);
502+
|| (side == Side::Client && mode == AsyncMode::Client)
503503
}

codegen/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'a> Iterator for NameSpliter<'a> {
3333
let mut meet_lower = false;
3434
for i in self.pos..self.name.len() {
3535
let c = self.name[i];
36-
if b'A' <= c && c <= b'Z' {
36+
if (b'A'..=b'Z').contains(&c) {
3737
if meet_lower {
3838
// So it should be AaA or aaA
3939
pos = i;

example2/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export PROTOC=${HOME}/protoc/bin/protoc
2+
13
#
24
# Build
35
#
@@ -20,3 +22,4 @@ deps:
2022
rustup update stable
2123
rustup default stable
2224
rustup component add rustfmt clippy
25+
../install_protoc.sh

0 commit comments

Comments
 (0)