refactor(multiple): Clippy run
This commit is contained in:
		| @@ -88,7 +88,7 @@ impl Connect for HttpConnector { | |||||||
|         if let Some(key) = self.key(url) { |         if let Some(key) = self.key(url) { | ||||||
|             let host = url.host_str().expect("http scheme must have a host"); |             let host = url.host_str().expect("http scheme must have a host"); | ||||||
|             self.dns.as_ref().expect("dns workers lost").resolve(host); |             self.dns.as_ref().expect("dns workers lost").resolve(host); | ||||||
|             self.resolving.entry(host.to_owned()).or_insert(Vec::new()).push(key.clone()); |             self.resolving.entry(host.to_owned()).or_insert_with(Vec::new).push(key.clone()); | ||||||
|             Ok(key) |             Ok(key) | ||||||
|         } else { |         } else { | ||||||
|             Err(io::Error::new(io::ErrorKind::InvalidInput, "scheme must be http")) |             Err(io::Error::new(io::ErrorKind::InvalidInput, "scheme must be http")) | ||||||
| @@ -101,25 +101,18 @@ impl Connect for HttpConnector { | |||||||
|             Err(_) => return None |             Err(_) => return None | ||||||
|         }; |         }; | ||||||
|         debug!("Http::resolved <- ({:?}, {:?})", host, addr); |         debug!("Http::resolved <- ({:?}, {:?})", host, addr); | ||||||
|         match self.resolving.entry(host) { |         if let Entry::Occupied(mut entry) = self.resolving.entry(host) { | ||||||
|             Entry::Occupied(mut entry) => { |  | ||||||
|             let resolved = entry.get_mut().remove(0); |             let resolved = entry.get_mut().remove(0); | ||||||
|             if entry.get().is_empty() { |             if entry.get().is_empty() { | ||||||
|                 entry.remove(); |                 entry.remove(); | ||||||
|             } |             } | ||||||
|             let port = resolved.2; |             let port = resolved.2; | ||||||
|                 match addr { |             Some((resolved, addr.and_then(|addr| TcpStream::connect(&SocketAddr::new(addr, port)) | ||||||
|                     Ok(addr) => { |                                                             .map(HttpStream)) | ||||||
|                         Some((resolved, TcpStream::connect(&SocketAddr::new(addr, port)) |                 )) | ||||||
|                             .map(HttpStream))) |         } else { | ||||||
|                     }, |  | ||||||
|                     Err(e) => Some((resolved, Err(e))) |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             _ => { |  | ||||||
|             trace!("^--  resolved but not in hashmap?"); |             trace!("^--  resolved but not in hashmap?"); | ||||||
|                 return None |             None | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -167,7 +160,7 @@ impl<S: SslClient> Connect for HttpsConnector<S> { | |||||||
|         if let Some(key) = self.key(url) { |         if let Some(key) = self.key(url) { | ||||||
|             let host = url.host_str().expect("http scheme must have a host"); |             let host = url.host_str().expect("http scheme must have a host"); | ||||||
|             self.http.dns.as_ref().expect("dns workers lost").resolve(host); |             self.http.dns.as_ref().expect("dns workers lost").resolve(host); | ||||||
|             self.http.resolving.entry(host.to_owned()).or_insert(Vec::new()).push(key.clone()); |             self.http.resolving.entry(host.to_owned()).or_insert_with(Vec::new).push(key.clone()); | ||||||
|             Ok(key) |             Ok(key) | ||||||
|         } else { |         } else { | ||||||
|             Err(io::Error::new(io::ErrorKind::InvalidInput, "scheme must be http or https")) |             Err(io::Error::new(io::ErrorKind::InvalidInput, "scheme must be http or https")) | ||||||
|   | |||||||
| @@ -440,7 +440,7 @@ where C: Connect, | |||||||
|                 let now = scope.now(); |                 let now = scope.now(); | ||||||
|                 let mut empty_keys = Vec::new(); |                 let mut empty_keys = Vec::new(); | ||||||
|                 { |                 { | ||||||
|                     for (key, mut vec) in scope.queue.iter_mut() { |                     for (key, mut vec) in &mut scope.queue { | ||||||
|                         while !vec.is_empty() && vec[0].deadline <= now { |                         while !vec.is_empty() && vec[0].deadline <= now { | ||||||
|                             let mut queued = vec.remove(0); |                             let mut queued = vec.remove(0); | ||||||
|                             let _ = queued.handler.on_error(::Error::Timeout); |                             let _ = queued.handler.on_error(::Error::Timeout); | ||||||
| @@ -517,7 +517,7 @@ where C: Connect, | |||||||
|                             match connector.connect(&url) { |                             match connector.connect(&url) { | ||||||
|                                 Ok(key) => { |                                 Ok(key) => { | ||||||
|                                     let deadline = scope.now() + scope.connect_timeout; |                                     let deadline = scope.now() + scope.connect_timeout; | ||||||
|                                     scope.queue.entry(key).or_insert(Vec::new()).push(Queued { |                                     scope.queue.entry(key).or_insert_with(Vec::new).push(Queued { | ||||||
|                                         deadline: deadline, |                                         deadline: deadline, | ||||||
|                                         handler: handler, |                                         handler: handler, | ||||||
|                                         url: url |                                         url: url | ||||||
|   | |||||||
| @@ -95,7 +95,7 @@ impl Display for RangeUnit { | |||||||
|         match *self { |         match *self { | ||||||
|             RangeUnit::Bytes => f.write_str("bytes"), |             RangeUnit::Bytes => f.write_str("bytes"), | ||||||
|             RangeUnit::None => f.write_str("none"), |             RangeUnit::None => f.write_str("none"), | ||||||
|             RangeUnit::Unregistered(ref x) => f.write_str(&x), |             RangeUnit::Unregistered(ref x) => f.write_str(x), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -182,7 +182,7 @@ impl Display for ContentRangeSpec { | |||||||
|             ContentRangeSpec::Unregistered { ref unit, ref resp } => { |             ContentRangeSpec::Unregistered { ref unit, ref resp } => { | ||||||
|                 try!(f.write_str(&unit)); |                 try!(f.write_str(&unit)); | ||||||
|                 try!(f.write_str(" ")); |                 try!(f.write_str(" ")); | ||||||
|                 f.write_str(&resp) |                 f.write_str(resp) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -69,14 +69,10 @@ impl Header for Host { | |||||||
|                 } |                 } | ||||||
|             }; |             }; | ||||||
|  |  | ||||||
|             let port = match idx { |             let port = idx.and_then(|idx| s[idx + 1..].parse().ok()); | ||||||
|                 Some(idx) => s[idx + 1..].parse().ok(), |  | ||||||
|                 None => None |  | ||||||
|             }; |  | ||||||
|  |  | ||||||
|             match idx { |             if let Some(idx) = idx { | ||||||
|                 Some(idx) => s.truncate(idx), |                 s.truncate(idx) | ||||||
|                 None => () |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             Ok(Host { |             Ok(Host { | ||||||
|   | |||||||
| @@ -106,7 +106,7 @@ impl fmt::Display for Preference { | |||||||
|             Extension(ref name, ref value, ref params) => { |             Extension(ref name, ref value, ref params) => { | ||||||
|                 try!(write!(f, "{}", name)); |                 try!(write!(f, "{}", name)); | ||||||
|                 if value != "" { try!(write!(f, "={}", value)); } |                 if value != "" { try!(write!(f, "={}", value)); } | ||||||
|                 if params.len() > 0 { |                 if !params.is_empty() { | ||||||
|                     for &(ref name, ref value) in params { |                     for &(ref name, ref value) in params { | ||||||
|                         try!(write!(f, "; {}", name)); |                         try!(write!(f, "; {}", name)); | ||||||
|                         if value != "" { try!(write!(f, "={}", value)); } |                         if value != "" { try!(write!(f, "={}", value)); } | ||||||
| @@ -138,12 +138,12 @@ impl FromStr for Preference { | |||||||
|             Some(param) => { |             Some(param) => { | ||||||
|                 let rest: Vec<(String, String)> = params.map(|(l, r)| (l.to_owned(), r.to_owned())).collect(); |                 let rest: Vec<(String, String)> = params.map(|(l, r)| (l.to_owned(), r.to_owned())).collect(); | ||||||
|                 match param { |                 match param { | ||||||
|                     ("respond-async", "") => if rest.len() == 0 { Ok(RespondAsync) } else { Err(None) }, |                     ("respond-async", "") => if rest.is_empty() { Ok(RespondAsync) } else { Err(None) }, | ||||||
|                     ("return", "representation") => if rest.len() == 0 { Ok(ReturnRepresentation) } else { Err(None) }, |                     ("return", "representation") => if rest.is_empty() { Ok(ReturnRepresentation) } else { Err(None) }, | ||||||
|                     ("return", "minimal") => if rest.len() == 0 { Ok(ReturnMinimal) } else { Err(None) }, |                     ("return", "minimal") => if rest.is_empty() { Ok(ReturnMinimal) } else { Err(None) }, | ||||||
|                     ("handling", "strict") => if rest.len() == 0 { Ok(HandlingStrict) } else { Err(None) }, |                     ("handling", "strict") => if rest.is_empty() { Ok(HandlingStrict) } else { Err(None) }, | ||||||
|                     ("handling", "leniant") => if rest.len() == 0 { Ok(HandlingLeniant) } else { Err(None) }, |                     ("handling", "leniant") => if rest.is_empty() { Ok(HandlingLeniant) } else { Err(None) }, | ||||||
|                     ("wait", secs) => if rest.len() == 0 { secs.parse().map(Wait).map_err(Some) } else { Err(None) }, |                     ("wait", secs) => if rest.is_empty() { secs.parse().map(Wait).map_err(Some) } else { Err(None) }, | ||||||
|                     (left, right) => Ok(Extension(left.to_owned(), right.to_owned(), rest)) |                     (left, right) => Ok(Extension(left.to_owned(), right.to_owned(), rest)) | ||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|   | |||||||
| @@ -71,7 +71,7 @@ impl Header for PreferenceApplied { | |||||||
|               value.to_owned(), |               value.to_owned(), | ||||||
|               vec![] |               vec![] | ||||||
|             ), |             ), | ||||||
|             preference @ _ => preference.clone() |             preference => preference.clone() | ||||||
|         }).collect(); |         }).collect(); | ||||||
|         fmt_comma_delimited(f, &preferences) |         fmt_comma_delimited(f, &preferences) | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -126,7 +126,7 @@ impl FromStr for Range { | |||||||
|     type Err = ::Error; |     type Err = ::Error; | ||||||
|  |  | ||||||
|     fn from_str(s: &str) -> ::Result<Range> { |     fn from_str(s: &str) -> ::Result<Range> { | ||||||
|         let mut iter = s.splitn(2, "="); |         let mut iter = s.splitn(2, '='); | ||||||
|  |  | ||||||
|         match (iter.next(), iter.next()) { |         match (iter.next(), iter.next()) { | ||||||
|             (Some("bytes"), Some(ranges)) => { |             (Some("bytes"), Some(ranges)) => { | ||||||
| @@ -153,7 +153,7 @@ impl FromStr for ByteRangeSpec { | |||||||
|     type Err = ::Error; |     type Err = ::Error; | ||||||
|  |  | ||||||
|     fn from_str(s: &str) -> ::Result<ByteRangeSpec> { |     fn from_str(s: &str) -> ::Result<ByteRangeSpec> { | ||||||
|         let mut parts = s.splitn(2, "-"); |         let mut parts = s.splitn(2, '-'); | ||||||
|  |  | ||||||
|         match (parts.next(), parts.next()) { |         match (parts.next(), parts.next()) { | ||||||
|             (Some(""), Some(end)) => { |             (Some(""), Some(end)) => { | ||||||
|   | |||||||
| @@ -143,12 +143,12 @@ impl<T: Header + Clone> HeaderClone for T { | |||||||
| impl Header + Send + Sync { | impl Header + Send + Sync { | ||||||
|     #[inline] |     #[inline] | ||||||
|     unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T { |     unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T { | ||||||
|         mem::transmute(traitobject::data(self)) |         &*(traitobject::data(self) as *const T) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     #[inline] |     #[inline] | ||||||
|     unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T { |     unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T { | ||||||
|         mem::transmute(traitobject::data_mut(self)) |         &mut *(traitobject::data_mut(self) as *mut T) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -497,7 +497,7 @@ impl<'a> fmt::Display for &'a (Header + Send + Sync) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| /// A wrapper around any Header with a Display impl that calls fmt_header. | /// A wrapper around any Header with a Display impl that calls `fmt_header`. | ||||||
| /// | /// | ||||||
| /// This can be used like so: `format!("{}", HeaderFormatter(&header))` to | /// This can be used like so: `format!("{}", HeaderFormatter(&header))` to | ||||||
| /// get the representation of a Header which will be written to an | /// get the representation of a Header which will be written to an | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ use header::shared::Charset; | |||||||
| pub fn from_one_raw_str<T: str::FromStr>(raw: &[Vec<u8>]) -> ::Result<T> { | pub fn from_one_raw_str<T: str::FromStr>(raw: &[Vec<u8>]) -> ::Result<T> { | ||||||
|     if raw.len() != 1 || unsafe { raw.get_unchecked(0) } == b"" { return Err(::Error::Header) } |     if raw.len() != 1 || unsafe { raw.get_unchecked(0) } == b"" { return Err(::Error::Header) } | ||||||
|     // we JUST checked that raw.len() == 1, so raw[0] WILL exist. |     // we JUST checked that raw.len() == 1, so raw[0] WILL exist. | ||||||
|     from_raw_str(& unsafe { raw.get_unchecked(0) }) |     from_raw_str( unsafe { raw.get_unchecked(0) }) | ||||||
| } | } | ||||||
|  |  | ||||||
| /// Reads a raw string into a value. | /// Reads a raw string into a value. | ||||||
|   | |||||||
| @@ -91,7 +91,7 @@ impl Charset { | |||||||
|             Gb2312 => "GB2312", |             Gb2312 => "GB2312", | ||||||
|             Big5 => "5", |             Big5 => "5", | ||||||
|             Koi8_R => "KOI8-R", |             Koi8_R => "KOI8-R", | ||||||
|             Ext(ref s) => &s |             Ext(ref s) => s | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,10 +4,10 @@ use std::fmt::{self, Display}; | |||||||
| // check that each char in the slice is either: | // check that each char in the slice is either: | ||||||
| // 1. %x21, or | // 1. %x21, or | ||||||
| // 2. in the range %x23 to %x7E, or | // 2. in the range %x23 to %x7E, or | ||||||
| // 3. in the range %x80 to %xFF | // 3. above %x80 | ||||||
| fn check_slice_validity(slice: &str) -> bool { | fn check_slice_validity(slice: &str) -> bool { | ||||||
|     slice.bytes().all(|c| |     slice.bytes().all(|c| | ||||||
|         c == b'\x21' || (c >= b'\x23' && c <= b'\x7e') | (c >= b'\x80' && c <= b'\xff')) |         c == b'\x21' || (c >= b'\x23' && c <= b'\x7e') | (c >= b'\x80')) | ||||||
| } | } | ||||||
|  |  | ||||||
| /// An entity tag, defined in [RFC7232](https://tools.ietf.org/html/rfc7232#section-2.3) | /// An entity tag, defined in [RFC7232](https://tools.ietf.org/html/rfc7232#section-2.3) | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ use std::ptr; | |||||||
| const INIT_BUFFER_SIZE: usize = 4096; | const INIT_BUFFER_SIZE: usize = 4096; | ||||||
| const MAX_BUFFER_SIZE: usize = 8192 + 4096 * 100; | const MAX_BUFFER_SIZE: usize = 8192 + 4096 * 100; | ||||||
|  |  | ||||||
| #[derive(Debug)] | #[derive(Debug, Default)] | ||||||
| pub struct Buffer { | pub struct Buffer { | ||||||
|     vec: Vec<u8>, |     vec: Vec<u8>, | ||||||
|     read_pos: usize, |     read_pos: usize, | ||||||
| @@ -15,11 +15,7 @@ pub struct Buffer { | |||||||
|  |  | ||||||
| impl Buffer { | impl Buffer { | ||||||
|     pub fn new() -> Buffer { |     pub fn new() -> Buffer { | ||||||
|         Buffer { |         Buffer::default() | ||||||
|             vec: Vec::new(), |  | ||||||
|             read_pos: 0, |  | ||||||
|             write_pos: 0, |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     pub fn reset(&mut self) { |     pub fn reset(&mut self) { | ||||||
|   | |||||||
| @@ -508,7 +508,7 @@ impl<K: Key, T: Transport, H: MessageHandler<T>> Conn<K, T, H> { | |||||||
|             }, |             }, | ||||||
|             Err(e) => { |             Err(e) => { | ||||||
|                 trace!("error reregistering: {:?}", e); |                 trace!("error reregistering: {:?}", e); | ||||||
|                 let _ = self.on_error(e.into()); |                 self.on_error(e.into()); | ||||||
|                 None |                 None | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -516,14 +516,9 @@ impl<K: Key, T: Transport, H: MessageHandler<T>> Conn<K, T, H> { | |||||||
|  |  | ||||||
|     pub fn wakeup<F>(mut self, scope: &mut Scope<F>) -> Option<(Self, Option<Duration>)> |     pub fn wakeup<F>(mut self, scope: &mut Scope<F>) -> Option<(Self, Option<Duration>)> | ||||||
|     where F: MessageHandlerFactory<K, T, Output=H> { |     where F: MessageHandlerFactory<K, T, Output=H> { | ||||||
|         loop { |         while let Ok(next) = self.ctrl.1.try_recv() { | ||||||
|             match self.ctrl.1.try_recv() { |  | ||||||
|                 Ok(next) => { |  | ||||||
|             trace!("woke up with {:?}", next); |             trace!("woke up with {:?}", next); | ||||||
|             self.state.update(next); |             self.state.update(next); | ||||||
|                 }, |  | ||||||
|                 Err(_) => break |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|         self.ready(EventSet::readable() | EventSet::writable(), scope) |         self.ready(EventSet::readable() | EventSet::writable(), scope) | ||||||
|     } |     } | ||||||
| @@ -872,7 +867,7 @@ impl<'a, K: Key + 'a> Seed<'a, K> { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     pub fn key(&self) -> &K { |     pub fn key(&self) -> &K { | ||||||
|         &self.0 |         self.0 | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,10 +6,10 @@ use net::Transport; | |||||||
|  |  | ||||||
| use super::{Handler, request, response}; | use super::{Handler, request, response}; | ||||||
|  |  | ||||||
| /// A MessageHandler for a Server. | /// A `MessageHandler` for a Server. | ||||||
| /// | /// | ||||||
| /// This should be really thin glue between http::MessageHandler and | /// This should be really thin glue between `http::MessageHandler` and | ||||||
| /// server::Handler, but largely just providing the proper types one | /// `server::Handler`, but largely just providing the proper types one | ||||||
| /// would expect in a Server Handler. | /// would expect in a Server Handler. | ||||||
| pub struct Message<H: Handler<T>, T: Transport> { | pub struct Message<H: Handler<T>, T: Transport> { | ||||||
|     handler: H, |     handler: H, | ||||||
| @@ -55,4 +55,3 @@ impl<H: Handler<T>, T: Transport> http::MessageHandler<T> for Message<H, T> { | |||||||
|         self.handler.on_remove(transport); |         self.handler.on_remove(transport); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -43,7 +43,7 @@ impl<'a> Response<'a> { | |||||||
| } | } | ||||||
|  |  | ||||||
| /// Creates a new Response that can be used to write to a network stream. | /// Creates a new Response that can be used to write to a network stream. | ||||||
| pub fn new<'a>(head: &'a mut http::MessageHead<StatusCode>) -> Response<'a> { | pub fn new(head: &mut http::MessageHead<StatusCode>) -> Response { | ||||||
|     Response { |     Response { | ||||||
|         head: head |         head: head | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user