Fixed clippy warnings (#90)

* Fixed clippy warnings

* Fix as per review
This commit is contained in:
boyned//Kampfkarren
2018-12-03 10:35:40 -08:00
committed by Lucien Greathouse
parent 26a7bb9746
commit 13a7c1ba81
7 changed files with 31 additions and 47 deletions

View File

@@ -100,11 +100,8 @@ impl FsWatcher {
thread::spawn(move || { thread::spawn(move || {
info!("Watcher thread ({}) started", root_path.display()); info!("Watcher thread ({}) started", root_path.display());
loop { while let Ok(event) = watch_rx.recv() {
match watch_rx.recv() { handle_event(&imfs, &rbx_session, event);
Ok(event) => handle_event(&imfs, &rbx_session, event),
Err(_) => break,
};
} }
info!("Watcher thread ({}) stopped", root_path.display()); info!("Watcher thread ({}) stopped", root_path.display());
}); });

View File

@@ -108,13 +108,10 @@ impl Imfs {
} }
} }
match self.items.remove(path) { if let Some(ImfsItem::Directory(directory)) = self.items.remove(path) {
Some(ImfsItem::Directory(directory)) => { for child_path in &directory.children {
for child_path in &directory.children { self.path_removed(child_path)?;
self.path_removed(child_path)?; }
}
},
_ => {},
} }
Ok(()) Ok(())
@@ -173,7 +170,7 @@ impl ImfsItem {
vfs.items.insert(path.to_path_buf(), item); vfs.items.insert(path.to_path_buf(), item);
Ok(vfs.items.get(path).unwrap()) Ok(&vfs.items[path])
} else if metadata.is_dir() { } else if metadata.is_dir() {
let mut children = HashSet::new(); let mut children = HashSet::new();
@@ -193,7 +190,7 @@ impl ImfsItem {
vfs.items.insert(path.to_path_buf(), item); vfs.items.insert(path.to_path_buf(), item);
Ok(vfs.items.get(path).unwrap()) Ok(&vfs.items[path])
} else { } else {
panic!("Unexpected non-file, non-directory item"); panic!("Unexpected non-file, non-directory item");
} }

View File

@@ -29,6 +29,7 @@ pub enum Message {
}, },
} }
#[derive(Default)]
pub struct MessageQueue { pub struct MessageQueue {
messages: RwLock<Vec<Message>>, messages: RwLock<Vec<Message>>,
message_listeners: Mutex<HashMap<ListenerId, mpsc::Sender<()>>>, message_listeners: Mutex<HashMap<ListenerId, mpsc::Sender<()>>>,

View File

@@ -192,15 +192,12 @@ impl Project {
} else if location_metadata.is_dir() { } else if location_metadata.is_dir() {
let with_file = start_location.join(PROJECT_FILENAME); let with_file = start_location.join(PROJECT_FILENAME);
match fs::metadata(&with_file) { if let Ok(with_file_metadata) = fs::metadata(&with_file) {
Ok(with_file_metadata) => { if with_file_metadata.is_file() {
if with_file_metadata.is_file() { return Some(with_file);
return Some(with_file); } else {
} else { return None;
return None; }
}
},
Err(_) => {},
} }
} }

View File

@@ -65,20 +65,15 @@ impl PathIdTree {
let root_id = root_node.id; let root_id = root_node.id;
let mut to_visit: Vec<PathBuf> = root_node.children.drain().collect(); let mut to_visit: Vec<PathBuf> = root_node.children.drain().collect();
loop { while let Some(path) = to_visit.pop() {
let next_path = match to_visit.pop() { match self.nodes.remove(&path) {
Some(path) => path,
None => break,
};
match self.nodes.remove(&next_path) {
Some(mut node) => { Some(mut node) => {
for child in node.children.drain() { for child in node.children.drain() {
to_visit.push(child); to_visit.push(child);
} }
}, },
None => { 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( construct_project_node(
&mut context, &mut context,
None, None,
project.name.clone(), &project.name,
&project.name, &project.name,
&project.tree, &project.tree,
); );
@@ -231,7 +226,7 @@ fn insert_or_create_tree(context: &mut ConstructContext, parent_instance_id: Opt
fn construct_project_node( fn construct_project_node(
context: &mut ConstructContext, context: &mut ConstructContext,
parent_instance_id: Option<RbxId>, parent_instance_id: Option<RbxId>,
instance_path: String, instance_path: &str,
instance_name: &str, instance_name: &str,
project_node: &ProjectNode, project_node: &ProjectNode,
) { ) {
@@ -264,7 +259,7 @@ fn construct_instance_node(
for (child_name, child_project_node) in &project_node.children { for (child_name, child_project_node) in &project_node.children {
let child_path = format!("{}/{}", instance_path, child_name); 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 id

View File

@@ -17,7 +17,7 @@ pub struct Session {
pub session_id: SessionId, pub session_id: SessionId,
pub message_queue: Arc<MessageQueue>, pub message_queue: Arc<MessageQueue>,
pub rbx_session: Arc<Mutex<RbxSession>>, pub rbx_session: Arc<Mutex<RbxSession>>,
fs_watcher: FsWatcher, _fs_watcher: FsWatcher,
} }
impl Session { impl Session {
@@ -44,7 +44,7 @@ impl Session {
session_id, session_id,
message_queue, message_queue,
rbx_session, rbx_session,
fs_watcher, _fs_watcher: fs_watcher,
}) })
} }

View File

@@ -54,7 +54,7 @@ pub struct Server {
impl Server { impl Server {
pub fn new(session: Arc<Session>) -> Server { pub fn new(session: Arc<Session>) -> Server {
Server { Server {
session: session, session,
server_version: env!("CARGO_PKG_VERSION"), server_version: env!("CARGO_PKG_VERSION"),
} }
} }
@@ -94,7 +94,7 @@ impl Server {
{ {
let (new_cursor, new_messages) = message_queue.get_messages_since(cursor); 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 { return Response::json(&SubscribeResponse {
session_id: self.session.session_id, session_id: self.session.session_id,
messages: Cow::Borrowed(&[]), messages: Cow::Borrowed(&[]),
@@ -129,7 +129,7 @@ impl Server {
let message_queue = Arc::clone(&self.session.message_queue); let message_queue = Arc::clone(&self.session.message_queue);
let requested_ids: Option<Vec<RbxId>> = id_list let requested_ids: Option<Vec<RbxId>> = id_list
.split(",") .split(',')
.map(RbxId::parse_str) .map(RbxId::parse_str)
.collect(); .collect();
@@ -146,15 +146,12 @@ impl Server {
let mut instances = HashMap::new(); let mut instances = HashMap::new();
for &requested_id in &requested_ids { for &requested_id in &requested_ids {
match tree.get_instance(requested_id) { if let Some(instance) = tree.get_instance(requested_id) {
Some(instance) => { instances.insert(instance.get_id(), Cow::Borrowed(instance));
instances.insert(instance.get_id(), Cow::Borrowed(instance));
for descendant in tree.descendants(requested_id) { for descendant in tree.descendants(requested_id) {
instances.insert(descendant.get_id(), Cow::Borrowed(descendant)); instances.insert(descendant.get_id(), Cow::Borrowed(descendant));
} }
},
None => {},
} }
} }