From 76e80ca9a317b38b820e5bfe67a9f29cab104918 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 25 Mar 2017 18:01:40 +0300 Subject: [PATCH] Only allocate error message if the error occurred Suggested by clippy: warning: use of `ok_or` followed by a function call --> src/handshake/server.rs:20:19 | 20 | let key = self.headers.find_first("Sec-WebSocket-Key") | ___________________^ starting here... 21 | | .ok_or(Error::Protocol("Missing Sec-WebSocket-Key".into()))?; | |_______________________________________________________________________^ ...ending here | = note: #[warn(or_fun_call)] on by default help: try this | let key = self.headers.find_first("Sec-WebSocket-Key").ok_or_else(|| Error::Protocol("Missing Sec-WebSocket-Key".into()))?; = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#or_fun_call --- src/client.rs | 2 +- src/handshake/server.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index d7b3f1f..63e4d8f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -73,7 +73,7 @@ fn wrap_stream(stream: TcpStream, _domain: &str, mode: Mode) -> Result(addrs: A, url: &Url, mode: Mode) -> Result where A: Iterator { - let domain = url.host_str().ok_or(Error::Url("No host name in the URL".into()))?; + let domain = url.host_str().ok_or_else(|| Error::Url("No host name in the URL".into()))?; for addr in addrs { debug!("Trying to contact {} at {}...", url, addr); if let Ok(raw_stream) = TcpStream::connect(addr) { diff --git a/src/handshake/server.rs b/src/handshake/server.rs index d389fd3..fbd08b6 100644 --- a/src/handshake/server.rs +++ b/src/handshake/server.rs @@ -18,7 +18,7 @@ impl Request { /// Reply to the response. pub fn reply(&self) -> Result> { let key = self.headers.find_first("Sec-WebSocket-Key") - .ok_or(Error::Protocol("Missing Sec-WebSocket-Key".into()))?; + .ok_or_else(|| Error::Protocol("Missing Sec-WebSocket-Key".into()))?; let reply = format!("\ HTTP/1.1 101 Switching Protocols\r\n\ Connection: Upgrade\r\n\