From bce4831ccba4c335e3781ad21455ad41b1025689 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 22 Nov 2018 14:27:07 -0500 Subject: [PATCH] Clippy clean --- Cargo.toml | 2 +- examples/gmail_oauth2.rs | 2 +- src/client.rs | 15 +++++++-------- src/extensions/idle.rs | 2 +- src/parse.rs | 12 ++++++------ src/types/fetch.rs | 6 +++--- src/types/mod.rs | 2 +- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 765a0b9..ec377b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "imap" -version = "0.9.0" +version = "0.9.1" authors = ["Matt McCoy ", "Jon Gjengset "] documentation = "https://docs.rs/imap/" diff --git a/examples/gmail_oauth2.rs b/examples/gmail_oauth2.rs index ff13f98..523d45f 100644 --- a/examples/gmail_oauth2.rs +++ b/examples/gmail_oauth2.rs @@ -31,7 +31,7 @@ fn main() { let ssl_connector = TlsConnector::builder().build().unwrap(); let client = imap::connect(socket_addr, domain, &ssl_connector).unwrap(); - let mut imap_session = match client.authenticate("XOAUTH2", gmail_auth) { + let mut imap_session = match client.authenticate("XOAUTH2", &gmail_auth) { Ok(c) => c, Err((e, _unauth_client)) => { println!("error authenticating: {}", e); diff --git a/src/client.rs b/src/client.rs index 2777c4a..8a996e5 100644 --- a/src/client.rs +++ b/src/client.rs @@ -305,7 +305,7 @@ impl Client { /// let domain = "imap.example.com"; /// let tls = TlsConnector::builder().build().unwrap(); /// let client = imap::connect((domain, 993), domain, &tls).unwrap(); - /// match client.authenticate("XOAUTH2", auth) { + /// match client.authenticate("XOAUTH2", &auth) { /// Ok(session) => { /// // you are successfully authenticated! /// }, @@ -320,13 +320,13 @@ impl Client { pub fn authenticate( mut self, auth_type: &str, - authenticator: A, + authenticator: &A, ) -> ::std::result::Result, (Error, Client)> { ok_or_unauth_client_err!( self.run_command(&format!("AUTHENTICATE {}", auth_type)), self ); - self.do_auth_handshake(&authenticator) + self.do_auth_handshake(authenticator) } /// This func does the handshake process once the authenticate command is made. @@ -905,7 +905,7 @@ impl Session { /// /// See [`extensions::idle::Handle`] for details. pub fn idle(&mut self) -> Result> { - extensions::idle::Handle::new(self) + extensions::idle::Handle::make(self) } /// The [`APPEND` command](https://tools.ietf.org/html/rfc3501#section-6.3.11) appends @@ -986,7 +986,7 @@ impl Session { /// - `SINCE `: Messages whose internal date (disregarding time and timezone) is within or later than the specified date. pub fn search(&mut self, query: &str) -> Result> { self.run_command_and_read_response(&format!("SEARCH {}", query)) - .and_then(|lines| parse_ids(lines, &mut self.unsolicited_responses_tx)) + .and_then(|lines| parse_ids(&lines, &mut self.unsolicited_responses_tx)) } /// Equivalent to [`Session::search`], except that the returned identifiers @@ -994,7 +994,7 @@ impl Session { /// command](https://tools.ietf.org/html/rfc3501#section-6.4.8). pub fn uid_search(&mut self, query: &str) -> Result> { self.run_command_and_read_response(&format!("UID SEARCH {}", query)) - .and_then(|lines| parse_ids(lines, &mut self.unsolicited_responses_tx)) + .and_then(|lines| parse_ids(&lines, &mut self.unsolicited_responses_tx)) } // these are only here because they are public interface, the rest is in `Connection` @@ -1266,8 +1266,7 @@ mod tests { b"foo".to_vec() } } - let auth = Authenticate::Auth; - let session = client.authenticate("PLAIN", auth).unwrap(); + let session = client.authenticate("PLAIN", &Authenticate::Auth).unwrap(); assert!( session.stream.get_ref().written_buf == command.as_bytes().to_vec(), "Invalid authenticate command" diff --git a/src/extensions/idle.rs b/src/extensions/idle.rs index 6fa570f..34ef1a7 100644 --- a/src/extensions/idle.rs +++ b/src/extensions/idle.rs @@ -45,7 +45,7 @@ pub trait SetReadTimeout { } impl<'a, T: Read + Write + 'a> Handle<'a, T> { - pub(crate) fn new(session: &'a mut Session) -> Result { + pub(crate) fn make(session: &'a mut Session) -> Result { let mut h = Handle { session, keepalive: Duration::from_secs(29 * 60), diff --git a/src/parse.rs b/src/parse.rs index ac6a315..04bcc35 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -82,7 +82,7 @@ where } }; - ZeroCopy::new(lines, f) + ZeroCopy::make(lines, f) } pub fn parse_names( @@ -209,7 +209,7 @@ pub fn parse_capabilities( } }; - unsafe { ZeroCopy::new(lines, f) } + unsafe { ZeroCopy::make(lines, f) } } pub fn parse_mailbox( @@ -294,7 +294,7 @@ pub fn parse_mailbox( } pub fn parse_ids( - lines: Vec, + lines: &[u8], unsolicited: &mut mpsc::Sender, ) -> Result> { let mut lines = &lines[..]; @@ -487,7 +487,7 @@ mod tests { * 1 RECENT\r\n\ * STATUS INBOX (MESSAGES 10 UIDNEXT 11 UIDVALIDITY 1408806928 UNSEEN 0)\r\n"; let (mut send, recv) = mpsc::channel(); - let ids = parse_ids(lines.to_vec(), &mut send).unwrap(); + let ids = parse_ids(lines, &mut send).unwrap(); assert_eq!(ids, [23, 42, 4711].iter().cloned().collect()); @@ -511,7 +511,7 @@ mod tests { let lines = b"* SEARCH 1600 1698 1739 1781 1795 1885 1891 1892 1893 1898 1899 1901 1911 1926 1932 1933 1993 1994 2007 2032 2033 2041 2053 2062 2063 2065 2066 2072 2078 2079 2082 2084 2095 2100 2101 2102 2103 2104 2107 2116 2120 2135 2138 2154 2163 2168 2172 2189 2193 2198 2199 2205 2212 2213 2221 2227 2267 2275 2276 2295 2300 2328 2330 2332 2333 2334\r\n\ * SEARCH 2335 2336 2337 2338 2339 2341 2342 2347 2349 2350 2358 2359 2362 2369 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2390 2392 2397 2400 2401 2403 2405 2409 2411 2414 2417 2419 2420 2424 2426 2428 2439 2454 2456 2467 2468 2469 2490 2515 2519 2520 2521\r\n"; let (mut send, recv) = mpsc::channel(); - let ids = parse_ids(lines.to_vec(), &mut send).unwrap(); + let ids = parse_ids(lines, &mut send).unwrap(); assert!(recv.try_recv().is_err()); let ids: HashSet = ids.iter().cloned().collect(); assert_eq!( @@ -534,7 +534,7 @@ mod tests { let lines = b"* SEARCH\r\n"; let (mut send, recv) = mpsc::channel(); - let ids = parse_ids(lines.to_vec(), &mut send).unwrap(); + let ids = parse_ids(lines, &mut send).unwrap(); assert!(recv.try_recv().is_err()); let ids: HashSet = ids.iter().cloned().collect(); assert_eq!(ids, HashSet::::new()); diff --git a/src/types/fetch.rs b/src/types/fetch.rs index e343757..6140c62 100644 --- a/src/types/fetch.rs +++ b/src/types/fetch.rs @@ -27,7 +27,7 @@ pub struct Fetch { impl Fetch { /// A list of flags that are set for this message. - pub fn flags<'a>(&'a self) -> &'a [Flag<'a>] { + pub fn flags(&self) -> &[Flag] { &self.flags[..] } @@ -106,7 +106,7 @@ impl Fetch { /// /// See [section 7.4.2 of RFC 3501](https://tools.ietf.org/html/rfc3501#section-7.4.2) for /// details. - pub fn section(&self, path: SectionPath) -> Option<&[u8]> { + pub fn section(&self, path: &SectionPath) -> Option<&[u8]> { self.fetch .iter() .filter_map(|av| match av { @@ -114,7 +114,7 @@ impl Fetch { section: Some(sp), data: Some(data), .. - } if sp == &path => Some(*data), + } if sp == path => Some(*data), _ => None, }) .next() diff --git a/src/types/mod.rs b/src/types/mod.rs index 73b3f10..09fc44d 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -285,7 +285,7 @@ impl ZeroCopy { /// `&self`. /// /// It is *not* safe for the error type `E` to borrow from the passed reference. - pub(crate) unsafe fn new(owned: Vec, derive: F) -> Result + pub(crate) unsafe fn make(owned: Vec, derive: F) -> Result where F: FnOnce(&'static [u8]) -> Result, {