From 8a1260ed48022f08c78c9b4a36392d17a3d5c312 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 17 Sep 2023 14:14:39 -0400 Subject: [PATCH] clippy --fix --- veilid-cli/src/client_api_connection.rs | 1 - veilid-cli/src/command_processor.rs | 12 +++++------- veilid-cli/src/main.rs | 2 +- veilid-cli/src/peers_table_view.rs | 2 +- veilid-cli/src/settings.rs | 4 ++-- veilid-cli/src/ui.rs | 25 +++++++++++------------- veilid-core/build.rs | 22 +++++++++------------ veilid-flutter/rust/src/dart_ffi.rs | 26 ++++++++++++------------- veilid-tools/src/assembly_buffer.rs | 12 +++++------- veilid-tools/src/split_url.rs | 2 +- veilid-tools/src/tools.rs | 8 +++----- 11 files changed, 51 insertions(+), 65 deletions(-) diff --git a/veilid-cli/src/client_api_connection.rs b/veilid-cli/src/client_api_connection.rs index 24923c58..cb39e5de 100644 --- a/veilid-cli/src/client_api_connection.rs +++ b/veilid-cli/src/client_api_connection.rs @@ -76,7 +76,6 @@ impl ClientApiConnection { }; if let Err(e) = reply_channel.send_async(response).await { error!("failed to process reply: {}", e); - return; } } diff --git a/veilid-cli/src/command_processor.rs b/veilid-cli/src/command_processor.rs index 4eb4337f..a9fe9168 100644 --- a/veilid-cli/src/command_processor.rs +++ b/veilid-cli/src/command_processor.rs @@ -248,7 +248,6 @@ Server Debug Commands: _ => { ui.add_node_event(Level::Error, format!("unknown flag: {}", flag)); ui.send_callback(callback); - return; } } }); @@ -271,7 +270,6 @@ Server Debug Commands: _ => { ui.add_node_event(Level::Error, format!("unknown flag: {}", flag)); ui.send_callback(callback); - return; } } }); @@ -399,12 +397,12 @@ Server Debug Commands: } pub fn update_route(&self, route: &json::JsonValue) { let mut out = String::new(); - if route["dead_routes"].len() != 0 { + if !route["dead_routes"].is_empty() { out.push_str(&format!("Dead routes: {:?}", route["dead_routes"])); } - if route["dead_routes"].len() != 0 { + if !route["dead_routes"].is_empty() { if !out.is_empty() { - out.push_str("\n"); + out.push('\n'); } out.push_str(&format!( "Dead remote routes: {:?}", @@ -460,7 +458,7 @@ Server Debug Commands: }; let strmsg = if printable { - format!("\"{}\"", String::from_utf8_lossy(&message).to_string()) + format!("\"{}\"", String::from_utf8_lossy(message)) } else { hex::encode(message) }; @@ -498,7 +496,7 @@ Server Debug Commands: }; let strmsg = if printable { - format!("\"{}\"", String::from_utf8_lossy(&message).to_string()) + format!("\"{}\"", String::from_utf8_lossy(message)) } else { hex::encode(message) }; diff --git a/veilid-cli/src/main.rs b/veilid-cli/src/main.rs index 11f0ebde..9345daaa 100644 --- a/veilid-cli/src/main.rs +++ b/veilid-cli/src/main.rs @@ -58,7 +58,7 @@ fn main() -> Result<(), String> { None }; - let mut settings = settings::Settings::new(settings_path.as_ref().map(|x| x.as_os_str())) + let mut settings = settings::Settings::new(settings_path.as_deref()) .map_err(|e| format!("configuration is invalid: {}", e))?; // Set config from command line diff --git a/veilid-cli/src/peers_table_view.rs b/veilid-cli/src/peers_table_view.rs index 6ba9639a..03d66795 100644 --- a/veilid-cli/src/peers_table_view.rs +++ b/veilid-cli/src/peers_table_view.rs @@ -58,7 +58,7 @@ impl TableViewItem for json::JsonValue { PeerTableColumn::NodeId => self["node_ids"][0].to_string(), PeerTableColumn::Address => self["peer_address"].to_string(), PeerTableColumn::LatencyAvg => { - format!("{}", format_ts(&self["peer_stats"]["latency"]["average"])) + format_ts(&self["peer_stats"]["latency"]["average"]).to_string() } PeerTableColumn::TransferDownAvg => { format_bps(&self["peer_stats"]["transfer"]["down"]["average"]) diff --git a/veilid-cli/src/settings.rs b/veilid-cli/src/settings.rs index 5cc9268f..73ecb29d 100644 --- a/veilid-cli/src/settings.rs +++ b/veilid-cli/src/settings.rs @@ -6,7 +6,7 @@ use std::net::{SocketAddr, ToSocketAddrs}; use std::path::{Path, PathBuf}; pub fn load_default_config() -> Result { - let default_config = r###"--- + let default_config = r#"--- address: "localhost:5959" autoconnect: true autoreconnect: true @@ -44,7 +44,7 @@ interface: info : "white" warn : "light yellow" error : "light red" - "### + "# .replace( "%LOGGING_FILE_DIRECTORY%", &Settings::get_default_log_directory().to_string_lossy(), diff --git a/veilid-cli/src/ui.rs b/veilid-cli/src/ui.rs index 24fcc803..c1e4642d 100644 --- a/veilid-cli/src/ui.rs +++ b/veilid-cli/src/ui.rs @@ -469,7 +469,7 @@ impl UI { let color = *Self::inner_mut(s).log_colors.get(&Level::Warn).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(">> Could not copy to clipboard"), + ">> Could not copy to clipboard".to_string(), ); } } else { @@ -482,15 +482,12 @@ impl UI { ) .as_bytes(), ) - .is_ok() - { - if std::io::stdout().flush().is_ok() { - let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); - cursive_flexi_logger_view::parse_lines_to_log( - color.into(), - format!(">> Copied: {}", text.as_ref()), - ); - } + .is_ok() && std::io::stdout().flush().is_ok() { + let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); + cursive_flexi_logger_view::parse_lines_to_log( + color.into(), + format!(">> Copied: {}", text.as_ref()), + ); } } } @@ -523,7 +520,7 @@ impl UI { let mut reset: bool = false; match state { ConnectionState::Disconnected => { - if inner.connection_dialog_state == None + if inner.connection_dialog_state.is_none() || inner .connection_dialog_state .as_ref() @@ -541,7 +538,7 @@ impl UI { } } ConnectionState::Connected(_, _) => { - if inner.connection_dialog_state != None + if inner.connection_dialog_state.is_some() && !inner .connection_dialog_state .as_ref() @@ -552,7 +549,7 @@ impl UI { } } ConnectionState::Retrying(_, _) => { - if inner.connection_dialog_state == None + if inner.connection_dialog_state.is_none() || inner .connection_dialog_state .as_ref() @@ -1020,7 +1017,7 @@ impl UISender { for l in 0..node_ids.len() { let nid = &node_ids[l]; if !node_id_str.is_empty() { - node_id_str.push_str(" "); + node_id_str.push(' '); } node_id_str.push_str(nid.to_string().as_ref()); } diff --git a/veilid-core/build.rs b/veilid-core/build.rs index 97d82650..c7ebbf9e 100644 --- a/veilid-core/build.rs +++ b/veilid-core/build.rs @@ -3,7 +3,7 @@ use std::process::{Command, Stdio}; fn search_file, P: AsRef>(start: T, name: P) -> Option { let start_path = PathBuf::from(start.as_ref()).canonicalize().ok(); - let mut path = start_path.as_ref().map(|x| x.as_path()); + let mut path = start_path.as_deref(); while let Some(some_path) = path { let file_path = some_path.join(name.as_ref()); if file_path.exists() { @@ -18,10 +18,8 @@ fn get_desired_capnp_version_string() -> String { let capnp_path = search_file(env!("CARGO_MANIFEST_DIR"), ".capnp_version") .expect("should find .capnp_version file"); std::fs::read_to_string(&capnp_path) - .expect(&format!( - "can't read .capnp_version file here: {:?}", - capnp_path - )) + .unwrap_or_else(|_| panic!("can't read .capnp_version file here: {:?}", + capnp_path)) .trim() .to_owned() } @@ -47,10 +45,8 @@ fn get_desired_protoc_version_string() -> String { let protoc_path = search_file(env!("CARGO_MANIFEST_DIR"), ".protoc_version") .expect("should find .protoc_version file"); std::fs::read_to_string(&protoc_path) - .expect(&format!( - "can't read .protoc_version file here: {:?}", - protoc_path - )) + .unwrap_or_else(|_| panic!("can't read .protoc_version file here: {:?}", + protoc_path)) .trim() .to_owned() } @@ -80,10 +76,10 @@ fn main() { // Check capnp version let desired_capnp_major_version = - usize::from_str_radix(desired_capnp_version_string.split_once(".").unwrap().0, 10) + usize::from_str_radix(desired_capnp_version_string.split_once('.').unwrap().0, 10) .expect("should be valid int"); - if usize::from_str_radix(capnp_version_string.split_once(".").unwrap().0, 10) + if usize::from_str_radix(capnp_version_string.split_once('.').unwrap().0, 10) .expect("should be valid int") != desired_capnp_major_version { @@ -100,9 +96,9 @@ fn main() { // Check protoc version let desired_protoc_major_version = - usize::from_str_radix(desired_protoc_version_string.split_once(".").unwrap().0, 10) + usize::from_str_radix(desired_protoc_version_string.split_once('.').unwrap().0, 10) .expect("should be valid int"); - if usize::from_str_radix(protoc_version_string.split_once(".").unwrap().0, 10) + if usize::from_str_radix(protoc_version_string.split_once('.').unwrap().0, 10) .expect("should be valid int") < desired_protoc_major_version { diff --git a/veilid-flutter/rust/src/dart_ffi.rs b/veilid-flutter/rust/src/dart_ffi.rs index 319d4e02..812f8ab9 100644 --- a/veilid-flutter/rust/src/dart_ffi.rs +++ b/veilid-flutter/rust/src/dart_ffi.rs @@ -358,7 +358,7 @@ pub extern "C" fn routing_context(port: i64) { let veilid_api = get_veilid_api().await?; let routing_context = veilid_api.routing_context(); let mut rc = ROUTING_CONTEXTS.lock(); - let new_id = add_routing_context(&mut *rc, routing_context); + let new_id = add_routing_context(&mut rc, routing_context); APIResult::Ok(new_id) }); } @@ -369,7 +369,7 @@ pub extern "C" fn release_routing_context(id: u32) -> i32 { if rc.remove(&id).is_none() { return 0; } - return 1; + 1 } #[no_mangle] @@ -381,8 +381,8 @@ pub extern "C" fn routing_context_with_privacy(id: u32) -> u32 { let Ok(routing_context) = routing_context.clone().with_privacy() else { return 0; }; - let new_id = add_routing_context(&mut rc, routing_context); - new_id + + add_routing_context(&mut rc, routing_context) } #[no_mangle] @@ -397,8 +397,8 @@ pub extern "C" fn routing_context_with_custom_privacy(id: u32, safety_selection: let Ok(routing_context) = routing_context.clone().with_custom_privacy(safety_selection) else { return 0; }; - let new_id = add_routing_context(&mut rc, routing_context); - new_id + + add_routing_context(&mut rc, routing_context) } #[no_mangle] @@ -411,8 +411,8 @@ pub extern "C" fn routing_context_with_sequencing(id: u32, sequencing: FfiStr) - return 0; }; let routing_context = routing_context.clone().with_sequencing(sequencing); - let new_id = add_routing_context(&mut rc, routing_context); - new_id + + add_routing_context(&mut rc, routing_context) } @@ -734,7 +734,7 @@ pub extern "C" fn release_table_db(id: u32) -> i32 { if rc.remove(&id).is_none() { return 0; } - return 1; + 1 } #[no_mangle] @@ -757,7 +757,7 @@ pub extern "C" fn table_db_get_column_count(id: u32) -> u32 { let Ok(cc) = table_db.clone().get_column_count() else { return 0; }; - return cc; + cc } #[no_mangle] @@ -794,8 +794,8 @@ pub extern "C" fn table_db_transact(id: u32) -> u32 { return 0; }; let tdbt = table_db.clone().transact(); - let tdbtid = add_table_db_transaction(tdbt); - return tdbtid; + + add_table_db_transaction(tdbt) } #[no_mangle] @@ -804,7 +804,7 @@ pub extern "C" fn release_table_db_transaction(id: u32) -> i32 { if tdbts.remove(&id).is_none() { return 0; } - return 1; + 1 } diff --git a/veilid-tools/src/assembly_buffer.rs b/veilid-tools/src/assembly_buffer.rs index 8154edc8..75ea4143 100644 --- a/veilid-tools/src/assembly_buffer.rs +++ b/veilid-tools/src/assembly_buffer.rs @@ -262,7 +262,7 @@ impl AssemblyBuffer { remote_addr: SocketAddr, ) -> NetworkResult>> { // If we receive a zero length frame, send it - if frame.len() == 0 { + if frame.is_empty() { return NetworkResult::value(Some(frame.to_vec())); } @@ -338,10 +338,8 @@ impl AssemblyBuffer { // If we are returning a message, see if there are any more assemblies for this peer // If not, remove the peer - if out.is_some() { - if peer_messages.assemblies.len() == 0 { - e.remove(); - } + if out.is_some() && peer_messages.assemblies.is_empty() { + e.remove(); } NetworkResult::value(out) } @@ -361,7 +359,7 @@ impl AssemblyBuffer { /// Add framing to chunk to send to the wire fn frame_chunk(chunk: &[u8], offset: usize, message_len: usize, seq: SequenceType) -> Vec { - assert!(chunk.len() > 0); + assert!(!chunk.is_empty()); assert!(message_len <= MAX_LEN); assert!(offset + chunk.len() <= message_len); @@ -403,7 +401,7 @@ impl AssemblyBuffer { } // Do not frame or split anything zero bytes long, just send it - if data.len() == 0 { + if data.is_empty() { return sender(data, remote_addr).await; } diff --git a/veilid-tools/src/split_url.rs b/veilid-tools/src/split_url.rs index 033ffc96..a9e24bb4 100644 --- a/veilid-tools/src/split_url.rs +++ b/veilid-tools/src/split_url.rs @@ -41,7 +41,7 @@ fn must_encode_path(c: u8) -> bool { fn is_valid_scheme>(host: H) -> bool { let mut chars = host.as_ref().chars(); if let Some(ch) = chars.next() { - if !matches!(ch, 'A'..='Z' | 'a'..='z') { + if !ch.is_ascii_alphabetic() { return false; } } else { diff --git a/veilid-tools/src/tools.rs b/veilid-tools/src/tools.rs index 648da9b2..d26f87b1 100644 --- a/veilid-tools/src/tools.rs +++ b/veilid-tools/src/tools.rs @@ -242,10 +242,8 @@ pub fn compatible_unspecified_socket_addr(socket_addr: &SocketAddr) -> SocketAdd pub fn listen_address_to_socket_addrs(listen_address: &str) -> Result, String> { // If no address is specified, but the port is, use ipv4 and ipv6 unspecified // If the address is specified, only use the specified port and fail otherwise - let ip_addrs = vec![ - IpAddr::V4(Ipv4Addr::UNSPECIFIED), - IpAddr::V6(Ipv6Addr::UNSPECIFIED), - ]; + let ip_addrs = [IpAddr::V4(Ipv4Addr::UNSPECIFIED), + IpAddr::V6(Ipv6Addr::UNSPECIFIED)]; Ok(if let Some(portstr) = listen_address.strip_prefix(':') { let port = portstr @@ -354,7 +352,7 @@ pub unsafe fn unaligned_u8_vec_uninit(n_bytes: usize) -> Vec { let ptr = unaligned.as_mut_ptr(); mem::forget(unaligned); - Vec::from_raw_parts(ptr as *mut u8, n_bytes, n_bytes) + Vec::from_raw_parts(ptr, n_bytes, n_bytes) } pub fn debug_backtrace() -> String {