From ca6ce3e1e6a7019ee5c0298379839c10a2ad766b Mon Sep 17 00:00:00 2001 From: tottoto Date: Sun, 3 Sep 2023 22:35:57 +0900 Subject: [PATCH] chore: Fix clippy warning --- codegen/src/main.rs | 12 ++++++------ examples/src/dynamic/server.rs | 10 ++-------- tonic-build/src/server.rs | 2 ++ tonic-web/src/call.rs | 4 ++-- tonic/src/codec/encode.rs | 4 ++-- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/codegen/src/main.rs b/codegen/src/main.rs index 4b88039a1..7659ad93d 100644 --- a/codegen/src/main.rs +++ b/codegen/src/main.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; fn main() { // tonic-health @@ -45,11 +45,11 @@ fn main() { } fn codegen( - root_dir: &PathBuf, + root_dir: &Path, iface_files: &[&str], include_dirs: &[&str], - out_dir: &PathBuf, - file_descriptor_set_path: &PathBuf, + out_dir: &Path, + file_descriptor_set_path: &Path, build_client: bool, build_server: bool, ) { @@ -59,12 +59,12 @@ fn codegen( .unwrap(); let iface_files: Vec = iface_files - .into_iter() + .iter() .map(|&path| root_dir.join(path)) .collect(); let include_dirs: Vec = include_dirs - .into_iter() + .iter() .map(|&path| root_dir.join(path)) .collect(); let out_dir = root_dir.join(out_dir); diff --git a/examples/src/dynamic/server.rs b/examples/src/dynamic/server.rs index e25c7e8ae..300ec868c 100644 --- a/examples/src/dynamic/server.rs +++ b/examples/src/dynamic/server.rs @@ -32,10 +32,7 @@ impl Echo for MyEcho { } fn init_echo(args: &[String], builder: &mut RoutesBuilder) { - let enabled = args - .into_iter() - .find(|arg| arg.as_str() == "echo") - .is_some(); + let enabled = args.iter().any(|arg| arg.as_str() == "echo"); if enabled { println!("Adding Echo service..."); let svc = EchoServer::new(MyEcho::default()); @@ -62,10 +59,7 @@ impl Greeter for MyGreeter { } fn init_greeter(args: &[String], builder: &mut RoutesBuilder) { - let enabled = args - .into_iter() - .find(|arg| arg.as_str() == "greeter") - .is_some(); + let enabled = args.iter().any(|arg| arg.as_str() == "greeter"); if enabled { println!("Adding Greeter service..."); diff --git a/tonic-build/src/server.rs b/tonic-build/src/server.rs index 9e42789ef..d9ab1ad6b 100644 --- a/tonic-build/src/server.rs +++ b/tonic-build/src/server.rs @@ -9,6 +9,7 @@ use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::{Ident, Lit, LitStr}; +#[allow(clippy::too_many_arguments)] pub(crate) fn generate_internal( service: &T, emit_package: bool, @@ -209,6 +210,7 @@ pub(crate) fn generate_internal( } } +#[allow(clippy::too_many_arguments)] fn generate_trait( service: &T, emit_package: bool, diff --git a/tonic-web/src/call.rs b/tonic-web/src/call.rs index c53c99720..8f472f945 100644 --- a/tonic-web/src/call.rs +++ b/tonic-web/src/call.rs @@ -415,7 +415,7 @@ fn make_trailers_frame(trailers: HeaderMap) -> Vec { /// or the buffer jsut contained grpc message frames. fn find_trailers(buf: &[u8]) -> Option { let mut len = 0; - let mut temp_buf = &buf[..]; + let mut temp_buf = buf; loop { // To check each frame, there must be at least GRPC_HEADER_SIZE @@ -440,7 +440,7 @@ fn find_trailers(buf: &[u8]) -> Option { return None; } - temp_buf = &buf[len as usize..]; + temp_buf = &buf[len..]; } } diff --git a/tonic/src/codec/encode.rs b/tonic/src/codec/encode.rs index bd48ee47b..593634f93 100644 --- a/tonic/src/codec/encode.rs +++ b/tonic/src/codec/encode.rs @@ -106,14 +106,14 @@ where BytesMut::new() }; - return EncodedBytes { + Self { source: Fuse::new(source), encoder, compression_encoding, max_message_size, buf, uncompression_buf, - }; + } } }