diff --git a/src/error.rs b/src/error.rs index 6fe7242e..5e71e022 100644 --- a/src/error.rs +++ b/src/error.rs @@ -45,13 +45,17 @@ impl DbErrorNew for DbError { hint: map.remove(&b'H'), position: match map.remove(&b'P') { Some(pos) => Some(ErrorPosition::Normal(try!(pos.parse().map_err(|_| ())))), - None => match map.remove(&b'p') { - Some(pos) => Some(ErrorPosition::Internal { - position: try!(pos.parse().map_err(|_| ())), - query: try!(map.remove(&b'q').ok_or(())), - }), - None => None, - }, + None => { + match map.remove(&b'p') { + Some(pos) => { + Some(ErrorPosition::Internal { + position: try!(pos.parse().map_err(|_| ())), + query: try!(map.remove(&b'q').ok_or(())), + }) + } + None => None, + } + } }, where_: map.remove(&b'W'), schema: map.remove(&b's'), @@ -231,8 +235,9 @@ impl error::Error for ConnectError { ConnectError::BadConnectParams(_) => "Error creating `ConnectParams`", ConnectError::MissingUser => "User missing in `ConnectParams`", ConnectError::DbError(_) => "Error reported by Postgres", - ConnectError::MissingPassword => - "The server requested a password but none was provided", + ConnectError::MissingPassword => { + "The server requested a password but none was provided" + } ConnectError::UnsupportedAuthentication => { "The server requested an unsupported authentication method" } diff --git a/src/io/mod.rs b/src/io/mod.rs index fbb4db01..bd2313f8 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -25,6 +25,9 @@ pub trait StreamWrapper: Read+Write+Send { /// /// If the `security-framework` Cargo feature is enabled, this trait will be /// implemented for `security_framework::secure_transport::ClientBuilder`. +/// +/// It is also implemented for `Fn(&str, Stream) -> Result, +/// Box` closures. pub trait NegotiateSsl { /// Negotiates an SSL session, returning a wrapper around the provided /// stream. @@ -36,3 +39,14 @@ pub trait NegotiateSsl { stream: Stream) -> Result, Box>; } + +impl NegotiateSsl for F + where F: Fn(&str, Stream) -> Result, Box> +{ + fn negotiate_ssl(&self, + host: &str, + stream: Stream) + -> Result, Box> { + (*self)(host, stream) + } +} diff --git a/src/lib.rs b/src/lib.rs index cd0a4972..6a67efeb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -477,7 +477,7 @@ impl InnerConnection { WHERE t.oid = $1") { Ok(..) => return Ok(()), Err(Error::IoError(e)) => return Err(ConnectError::IoError(e)), - // Range types weren't added until Postgres 9.2, so pg_range may not exist + // Range types weren't added until Postgres 9.2, so pg_range may not exist Err(Error::DbError(ref e)) if e.code() == &SqlState::UndefinedTable => {} Err(Error::DbError(e)) => return Err(ConnectError::DbError(e)), _ => unreachable!(), @@ -825,8 +825,7 @@ impl InnerConnection { } fn _ensure_send() { - fn _is_send() { - } + fn _is_send() {} _is_send::(); } diff --git a/src/md5.rs b/src/md5.rs index 1656609c..e255d582 100644 --- a/src/md5.rs +++ b/src/md5.rs @@ -21,8 +21,8 @@ struct StepUp { ammount: T, } -impl Iterator for StepUp where - T: Add + PartialOrd + Copy { +impl Iterator for StepUp where T: Add + PartialOrd + Copy +{ type Item = T; #[inline] @@ -41,8 +41,8 @@ trait RangeExt { fn step_up(self, ammount: T) -> StepUp; } -impl RangeExt for Range where - T: Add + PartialOrd + Copy { +impl RangeExt for Range where T: Add + PartialOrd + Copy +{ fn step_up(self, ammount: T) -> StepUp { StepUp { next: self.start, @@ -108,7 +108,7 @@ trait StandardPadding { fn standard_padding(&mut self, rem: usize, func: F); } -impl StandardPadding for T { +impl StandardPadding for T { fn standard_padding(&mut self, rem: usize, mut func: F) { let size = self.size(); diff --git a/src/message.rs b/src/message.rs index b46a1b10..18d0cf9a 100644 --- a/src/message.rs +++ b/src/message.rs @@ -323,11 +323,13 @@ impl ReadMessage for R { b'1' => ParseComplete, b'2' => BindComplete, b'3' => CloseComplete, - b'A' => NotificationResponse { - pid: try!(rdr.read_u32::()), - channel: try!(rdr.read_cstr()), - payload: try!(rdr.read_cstr()), - }, + b'A' => { + NotificationResponse { + pid: try!(rdr.read_u32::()), + channel: try!(rdr.read_cstr()), + payload: try!(rdr.read_cstr()), + } + } b'c' => BCopyDone, b'C' => CommandComplete { tag: try!(rdr.read_cstr()) }, b'd' => { @@ -360,23 +362,29 @@ impl ReadMessage for R { } } b'I' => EmptyQueryResponse, - b'K' => BackendKeyData { - process_id: try!(rdr.read_u32::()), - secret_key: try!(rdr.read_u32::()), - }, + b'K' => { + BackendKeyData { + process_id: try!(rdr.read_u32::()), + secret_key: try!(rdr.read_u32::()), + } + } b'n' => NoData, b'N' => NoticeResponse { fields: try!(read_fields(&mut rdr)) }, b'R' => try!(read_auth_message(&mut rdr)), b's' => PortalSuspended, - b'S' => ParameterStatus { - parameter: try!(rdr.read_cstr()), - value: try!(rdr.read_cstr()), - }, + b'S' => { + ParameterStatus { + parameter: try!(rdr.read_cstr()), + value: try!(rdr.read_cstr()), + } + } b't' => try!(read_parameter_description(&mut rdr)), b'T' => try!(read_row_description(&mut rdr)), b'Z' => ReadyForQuery { _state: try!(rdr.read_u8()) }, - t => return Err(io::Error::new(io::ErrorKind::Other, - format!("unexpected message tag `{}`", t))), + t => { + return Err(io::Error::new(io::ErrorKind::Other, + format!("unexpected message tag `{}`", t))) + } }; if rdr.limit() != 0 { return Err(io::Error::new(io::ErrorKind::Other, "didn't read entire message")); @@ -431,8 +439,10 @@ fn read_auth_message(buf: &mut R) -> io::Result { 6 => AuthenticationSCMCredential, 7 => AuthenticationGSS, 9 => AuthenticationSSPI, - t => return Err(io::Error::new(io::ErrorKind::Other, - format!("unexpected authentication tag `{}`", t))), + t => { + return Err(io::Error::new(io::ErrorKind::Other, + format!("unexpected authentication tag `{}`", t))) + } }) } diff --git a/src/priv_io.rs b/src/priv_io.rs index 788a722b..c111ba69 100644 --- a/src/priv_io.rs +++ b/src/priv_io.rs @@ -28,8 +28,9 @@ pub trait ReadTimeout { impl ReadTimeout for BufStream> { fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { match self.get_ref().get_ref().0 { - InternalStream::Tcp(ref s) => - ::set_read_timeout(s, timeout), + InternalStream::Tcp(ref s) => { + ::set_read_timeout(s, timeout) + } #[cfg(feature = "unix_socket")] InternalStream::Unix(ref s) => s.set_read_timeout(timeout), } diff --git a/src/types/mod.rs b/src/types/mod.rs index 7ad02213..63cfdd4a 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -827,7 +827,8 @@ pub trait ToSql: fmt::Debug { fn to_sql_checked(&self, ty: &Type, out: &mut Write, ctx: &SessionInfo) -> Result; } -impl<'a, T> ToSql for &'a T where T: ToSql { +impl<'a, T> ToSql for &'a T where T: ToSql +{ to_sql_checked!(); fn to_sql(&self, diff --git a/src/url.rs b/src/url.rs index 1298afd1..192778b5 100644 --- a/src/url.rs +++ b/src/url.rs @@ -121,45 +121,49 @@ fn decode_inner(c: &str, full_url: bool) -> DecodeResult { loop { match iter.next() { - Some(b) => match b as char { - '%' => { - let bytes = match (iter.next(), iter.next()) { - (Some(one), Some(two)) => [one, two], - _ => return Err(format!("Malformed input: found '%' without two \ - trailing bytes")), - }; + Some(b) => { + match b as char { + '%' => { + let bytes = match (iter.next(), iter.next()) { + (Some(one), Some(two)) => [one, two], + _ => { + return Err(format!("Malformed input: found '%' without two \ + trailing bytes")) + } + }; - // Only decode some characters if full_url: - match str::from_utf8(&bytes).unwrap().from_hex().unwrap()[0] as char { - // gen-delims: - ':' | - '/' | - '?' | - '#' | - '[' | - ']' | - '@' | - '!' | - '$' | - '&' | - '"' | - '(' | - ')' | - '*' | - '+' | - ',' | - ';' | - '=' if full_url => { - out.push('%'); - out.push(bytes[0] as char); - out.push(bytes[1] as char); + // Only decode some characters if full_url: + match str::from_utf8(&bytes).unwrap().from_hex().unwrap()[0] as char { + // gen-delims: + ':' | + '/' | + '?' | + '#' | + '[' | + ']' | + '@' | + '!' | + '$' | + '&' | + '"' | + '(' | + ')' | + '*' | + '+' | + ',' | + ';' | + '=' if full_url => { + out.push('%'); + out.push(bytes[0] as char); + out.push(bytes[1] as char); + } + + ch => out.push(ch), } - - ch => out.push(ch), } + ch => out.push(ch), } - ch => out.push(ch), - }, + } None => return Ok(out), } } @@ -384,10 +388,12 @@ fn get_authority(rawurl: &str) -> DecodeResult<(Option, &str, Option None, - opt => match opt.and_then(|p| FromStr::from_str(p).ok()) { - None => return Err(format!("Failed to parse port: {:?}", port)), - opt => opt, - }, + opt => { + match opt.and_then(|p| FromStr::from_str(p).ok()) { + None => return Err(format!("Failed to parse port: {:?}", port)), + opt => opt, + } + } }; Ok((userinfo, host, port, rest))