From 0b46b951ae088dd22fe980acc7d855947ce2537f Mon Sep 17 00:00:00 2001 From: Byron Hsu Date: Tue, 26 Nov 2024 15:00:41 -0800 Subject: [PATCH] Fix rust warning (#2208) --- rust/src/router.rs | 6 ++---- rust/src/server.rs | 2 +- rust/src/tree.rs | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/rust/src/router.rs b/rust/src/router.rs index 0976b7f5e..e17cba874 100644 --- a/rust/src/router.rs +++ b/rust/src/router.rs @@ -2,12 +2,10 @@ use crate::tree::Tree; use actix_web::http::header::{HeaderValue, CONTENT_TYPE}; use actix_web::{HttpRequest, HttpResponse}; use bytes::Bytes; -use futures_util::{Stream, StreamExt, TryStreamExt}; +use futures_util::{StreamExt, TryStreamExt}; use log::{debug, info}; use std::collections::HashMap; use std::fmt::Debug; -use std::hash::Hash; -use std::pin::Pin; use std::sync::atomic::AtomicUsize; use std::sync::{Arc, Mutex}; use std::thread; @@ -252,7 +250,7 @@ impl Router { } => { // TODO: delay scheduling if cache hit rate is high because it may cause imbalance. prioritize low hit rate ones - let mut tree = tree.lock().unwrap(); + let tree = tree.lock().unwrap(); let mut running_queue = running_queue.lock().unwrap(); // Get current load statistics diff --git a/rust/src/server.rs b/rust/src/server.rs index 5a0ff5c5c..3fbe5c3e8 100644 --- a/rust/src/server.rs +++ b/rust/src/server.rs @@ -3,7 +3,7 @@ use crate::router::Router; use actix_web::{get, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder}; use bytes::Bytes; use env_logger::Builder; -use log::{debug, info, LevelFilter}; +use log::{info, LevelFilter}; use std::io::Write; #[derive(Debug)] diff --git a/rust/src/tree.rs b/rust/src/tree.rs index fcec5f578..3c403676f 100644 --- a/rust/src/tree.rs +++ b/rust/src/tree.rs @@ -1,15 +1,13 @@ use dashmap::mapref::entry::Entry; use dashmap::DashMap; use log::info; -use rand::distributions::{Alphanumeric, DistString}; -use rand::thread_rng; -use std::cmp::min; + use std::cmp::Reverse; use std::collections::BinaryHeap; use std::collections::HashMap; use std::sync::Arc; use std::sync::RwLock; -use std::thread; + use std::time::Duration; use std::time::{SystemTime, UNIX_EPOCH}; @@ -248,6 +246,7 @@ impl Tree { } } + #[allow(unused_assignments)] pub fn prefix_match(&self, text: &str) -> (String, String) { let mut curr = Arc::clone(&self.root); let mut curr_idx = 0; @@ -317,6 +316,7 @@ impl Tree { (ret_text, tenant) } + #[allow(unused_assignments)] pub fn prefix_match_tenant(&self, text: &str, tenant: &str) -> String { let mut curr = Arc::clone(&self.root); let mut curr_idx = 0; @@ -632,9 +632,12 @@ impl Tree { // Unit tests #[cfg(test)] mod tests { - use std::time::Instant; - + use rand::distributions::Alphanumeric; + use rand::distributions::DistString; + use rand::thread_rng; use rand::Rng; + use std::thread; + use std::time::Instant; use super::*; @@ -1026,7 +1029,7 @@ mod tests { let text = prefix[i]; let handle = thread::spawn(move || { - let (matched_text, matched_tenant) = tree_clone.prefix_match(text); + let (_matched_text, _matched_tenant) = tree_clone.prefix_match(text); }); handles.push(handle); @@ -1169,7 +1172,7 @@ mod tests { let prefixes = vec!["aqwefcisdf", "iajsdfkmade", "kjnzxcvewqe", "iejksduqasd"]; // Insert strings with shared prefixes - for i in 0..100 { + for _i in 0..100 { for (j, prefix) in prefixes.iter().enumerate() { let random_suffix = random_string(10); let text = format!("{}{}", prefix, random_suffix); @@ -1234,7 +1237,7 @@ mod tests { // Perform match operation let random_len = rng.gen_range(3..10); let search_str = format!("{}{}", prefix, random_string(random_len)); - let (matched, _) = tree.prefix_match(&search_str); + let (_matched, _) = tree.prefix_match(&search_str); } else { // Perform insert operation let random_len = rng.gen_range(5..15);