diff --git a/src/core/scenegraph.rs b/src/core/scenegraph.rs index 214c9f8..afbe3d6 100644 --- a/src/core/scenegraph.rs +++ b/src/core/scenegraph.rs @@ -24,9 +24,7 @@ impl<'a> Scenegraph<'a> { } pub fn get_node(&self, path: &str) -> Weak>> { - self.nodes - .get(path) - .map_or(Weak::default(), |node| Rc::downgrade(node)) + self.nodes.get(path).map_or(Weak::default(), Rc::downgrade) } } diff --git a/src/main.rs b/src/main.rs index ee213c4..70b9b8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,6 @@ mod core; mod nodes; use self::core::eventloop::EventLoop; - -use ctrlc; use std::sync::mpsc::channel; fn main() { diff --git a/src/nodes/core.rs b/src/nodes/core.rs index 580d5b1..b560965 100644 --- a/src/nodes/core.rs +++ b/src/nodes/core.rs @@ -41,7 +41,9 @@ impl<'a> Node<'a> { } let node = Node { path: path.to_string(), - trailing_slash_pos: path.rfind('/').ok_or(anyhow!("Invalid path {}", path))?, + trailing_slash_pos: path + .rfind('/') + .ok_or_else(|| anyhow!("Invalid path {}", path))?, messenger: weak_messenger, local_signals: HashMap::new(), local_methods: HashMap::new(), @@ -50,28 +52,29 @@ impl<'a> Node<'a> { }; let node_ref = Rc::new(RefCell::new(node)); let weak_node = Rc::downgrade(&node_ref); - if client.is_some() { - client.unwrap().scenegraph.add_node(node_ref); - } + match client { + Some(client_) => client_.scenegraph.add_node(node_ref), + None => {} + }; Ok(weak_node) } pub fn send_local_signal(&self, method: &str, data: &[u8]) -> Result<()> { self.local_signals .get(method) - .ok_or(anyhow!("Signal {} not found", method))?(data); + .ok_or_else(|| anyhow!("Signal {} not found", method))?(data); Ok(()) } pub fn execute_local_method(&self, method: &str, data: &[u8]) -> Result> { Ok(self .local_methods .get(method) - .ok_or(anyhow!("Method {} not found", method))?(data)) + .ok_or_else(|| anyhow!("Method {} not found", method))?(data)) } pub fn send_remote_signal(&self, method: &str, data: &[u8]) -> Result<()> { self.messenger .upgrade() - .ok_or(anyhow!("Invalid messenger"))? + .ok_or_else(|| anyhow!("Invalid messenger"))? .send_remote_signal(self.path.as_str(), method, data) .map_err(|_| anyhow!("Unable to write in messenger")) } @@ -83,7 +86,7 @@ impl<'a> Node<'a> { ) -> Result<()> { self.messenger .upgrade() - .ok_or(anyhow!("Invalid messenger"))? + .ok_or_else(|| anyhow!("Invalid messenger"))? .execute_remote_method(self.path.as_str(), method, data, callback) .map_err(|_| anyhow!("Unable to write in messenger")) }