From 13a7c1ba81aa98cbd212422d2aa78991c9781920 Mon Sep 17 00:00:00 2001 From: boyned//Kampfkarren Date: Mon, 3 Dec 2018 10:35:40 -0800 Subject: [PATCH] Fixed clippy warnings (#90) * Fixed clippy warnings * Fix as per review --- server/src/fs_watcher.rs | 7 ++----- server/src/imfs.rs | 15 ++++++--------- server/src/message_queue.rs | 1 + server/src/project.rs | 15 ++++++--------- server/src/rbx_session.rs | 17 ++++++----------- server/src/session.rs | 4 ++-- server/src/web.rs | 19 ++++++++----------- 7 files changed, 31 insertions(+), 47 deletions(-) diff --git a/server/src/fs_watcher.rs b/server/src/fs_watcher.rs index a48319ef..9737aa4e 100644 --- a/server/src/fs_watcher.rs +++ b/server/src/fs_watcher.rs @@ -100,11 +100,8 @@ impl FsWatcher { thread::spawn(move || { info!("Watcher thread ({}) started", root_path.display()); - loop { - match watch_rx.recv() { - Ok(event) => handle_event(&imfs, &rbx_session, event), - Err(_) => break, - }; + while let Ok(event) = watch_rx.recv() { + handle_event(&imfs, &rbx_session, event); } info!("Watcher thread ({}) stopped", root_path.display()); }); diff --git a/server/src/imfs.rs b/server/src/imfs.rs index 47ca782a..40d81d6f 100644 --- a/server/src/imfs.rs +++ b/server/src/imfs.rs @@ -108,13 +108,10 @@ impl Imfs { } } - match self.items.remove(path) { - Some(ImfsItem::Directory(directory)) => { - for child_path in &directory.children { - self.path_removed(child_path)?; - } - }, - _ => {}, + if let Some(ImfsItem::Directory(directory)) = self.items.remove(path) { + for child_path in &directory.children { + self.path_removed(child_path)?; + } } Ok(()) @@ -173,7 +170,7 @@ impl ImfsItem { vfs.items.insert(path.to_path_buf(), item); - Ok(vfs.items.get(path).unwrap()) + Ok(&vfs.items[path]) } else if metadata.is_dir() { let mut children = HashSet::new(); @@ -193,7 +190,7 @@ impl ImfsItem { vfs.items.insert(path.to_path_buf(), item); - Ok(vfs.items.get(path).unwrap()) + Ok(&vfs.items[path]) } else { panic!("Unexpected non-file, non-directory item"); } diff --git a/server/src/message_queue.rs b/server/src/message_queue.rs index c7f75133..7c8280f6 100644 --- a/server/src/message_queue.rs +++ b/server/src/message_queue.rs @@ -29,6 +29,7 @@ pub enum Message { }, } +#[derive(Default)] pub struct MessageQueue { messages: RwLock>, message_listeners: Mutex>>, diff --git a/server/src/project.rs b/server/src/project.rs index 0221f7fc..e67834de 100644 --- a/server/src/project.rs +++ b/server/src/project.rs @@ -192,15 +192,12 @@ impl Project { } else if location_metadata.is_dir() { let with_file = start_location.join(PROJECT_FILENAME); - match fs::metadata(&with_file) { - Ok(with_file_metadata) => { - if with_file_metadata.is_file() { - return Some(with_file); - } else { - return None; - } - }, - Err(_) => {}, + if let Ok(with_file_metadata) = fs::metadata(&with_file) { + if with_file_metadata.is_file() { + return Some(with_file); + } else { + return None; + } } } diff --git a/server/src/rbx_session.rs b/server/src/rbx_session.rs index ca722fd0..705a6ecd 100644 --- a/server/src/rbx_session.rs +++ b/server/src/rbx_session.rs @@ -65,20 +65,15 @@ impl PathIdTree { let root_id = root_node.id; let mut to_visit: Vec = root_node.children.drain().collect(); - loop { - let next_path = match to_visit.pop() { - Some(path) => path, - None => break, - }; - - match self.nodes.remove(&next_path) { + while let Some(path) = to_visit.pop() { + match self.nodes.remove(&path) { Some(mut node) => { for child in node.children.drain() { to_visit.push(child); } }, None => { - warn!("Consistency issue; tried to remove {} but it was already removed", next_path.display()); + warn!("Consistency issue; tried to remove {} but it was already removed", path.display()); }, } } @@ -203,7 +198,7 @@ fn construct_initial_tree( construct_project_node( &mut context, None, - project.name.clone(), + &project.name, &project.name, &project.tree, ); @@ -231,7 +226,7 @@ fn insert_or_create_tree(context: &mut ConstructContext, parent_instance_id: Opt fn construct_project_node( context: &mut ConstructContext, parent_instance_id: Option, - instance_path: String, + instance_path: &str, instance_name: &str, project_node: &ProjectNode, ) { @@ -264,7 +259,7 @@ fn construct_instance_node( for (child_name, child_project_node) in &project_node.children { let child_path = format!("{}/{}", instance_path, child_name); - construct_project_node(context, Some(id), child_path, child_name, child_project_node); + construct_project_node(context, Some(id), &child_path, child_name, child_project_node); } id diff --git a/server/src/session.rs b/server/src/session.rs index 90488124..5fb589f6 100644 --- a/server/src/session.rs +++ b/server/src/session.rs @@ -17,7 +17,7 @@ pub struct Session { pub session_id: SessionId, pub message_queue: Arc, pub rbx_session: Arc>, - fs_watcher: FsWatcher, + _fs_watcher: FsWatcher, } impl Session { @@ -44,7 +44,7 @@ impl Session { session_id, message_queue, rbx_session, - fs_watcher, + _fs_watcher: fs_watcher, }) } diff --git a/server/src/web.rs b/server/src/web.rs index 168db49b..bae32228 100644 --- a/server/src/web.rs +++ b/server/src/web.rs @@ -54,7 +54,7 @@ pub struct Server { impl Server { pub fn new(session: Arc) -> Server { Server { - session: session, + session, server_version: env!("CARGO_PKG_VERSION"), } } @@ -94,7 +94,7 @@ impl Server { { let (new_cursor, new_messages) = message_queue.get_messages_since(cursor); - if new_messages.len() > 0 { + if !new_messages.is_empty() { return Response::json(&SubscribeResponse { session_id: self.session.session_id, messages: Cow::Borrowed(&[]), @@ -129,7 +129,7 @@ impl Server { let message_queue = Arc::clone(&self.session.message_queue); let requested_ids: Option> = id_list - .split(",") + .split(',') .map(RbxId::parse_str) .collect(); @@ -146,15 +146,12 @@ impl Server { let mut instances = HashMap::new(); for &requested_id in &requested_ids { - match tree.get_instance(requested_id) { - Some(instance) => { - instances.insert(instance.get_id(), Cow::Borrowed(instance)); + if let Some(instance) = tree.get_instance(requested_id) { + instances.insert(instance.get_id(), Cow::Borrowed(instance)); - for descendant in tree.descendants(requested_id) { - instances.insert(descendant.get_id(), Cow::Borrowed(descendant)); - } - }, - None => {}, + for descendant in tree.descendants(requested_id) { + instances.insert(descendant.get_id(), Cow::Borrowed(descendant)); + } } }