From f7c0038fa3773f95b6f4d189bea0562ec8cd3531 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 15 Aug 2014 19:50:11 -0700 Subject: [PATCH] Formatting cleanup --- src/lib.rs | 101 +++++++++++++++++++++----------------------------- tests/test.rs | 3 +- 2 files changed, 44 insertions(+), 60 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5cf244ef..ff9714cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -192,20 +192,17 @@ pub struct PostgresConnectParams { /// `PostgresConnectParams`. pub trait IntoConnectParams { /// Converts the value of `self` into a `PostgresConnectParams`. - fn into_connect_params(self) -> Result; + fn into_connect_params(self) -> Result; } impl IntoConnectParams for PostgresConnectParams { - fn into_connect_params(self) -> Result { + fn into_connect_params(self) -> Result { Ok(self) } } impl<'a> IntoConnectParams for &'a str { - fn into_connect_params(self) -> Result { + fn into_connect_params(self) -> Result { match Url::parse(self) { Ok(url) => url.into_connect_params(), Err(err) => return Err(InvalidUrl(err)), @@ -214,8 +211,7 @@ impl<'a> IntoConnectParams for &'a str { } impl IntoConnectParams for Url { - fn into_connect_params(self) -> Result { + fn into_connect_params(self) -> Result { let Url { host, port, @@ -336,8 +332,7 @@ pub struct PostgresCancelData { /// # let _ = /// postgres::cancel_query(url, &NoSsl, cancel_data); /// ``` -pub fn cancel_query(params: T, ssl: &SslMode, - data: PostgresCancelData) +pub fn cancel_query(params: T, ssl: &SslMode, data: PostgresCancelData) -> Result<(), PostgresConnectError> { let params = try!(params.into_connect_params()); @@ -379,8 +374,7 @@ impl Drop for InnerPostgresConnection { impl InnerPostgresConnection { fn connect(params: T, ssl: &SslMode) - -> Result { + -> Result { let params = try!(params.into_connect_params()); let stream = try!(io::initialize_stream(¶ms, ssl)); @@ -456,23 +450,25 @@ impl InnerPostgresConnection { debug_assert!(!self.desynchronized); loop { match try_desync!(self, self.stream.read_message()) { - NoticeResponse { fields } => - self.notice_handler.handle(PostgresDbError::new(fields)), - NotificationResponse { pid, channel, payload } => + NoticeResponse { fields } => { + self.notice_handler.handle(PostgresDbError::new(fields)) + } + NotificationResponse { pid, channel, payload } => { self.notifications.push(PostgresNotification { pid: pid, channel: channel, payload: payload - }), - ParameterStatus { parameter, value } => - debug!("Parameter {} = {}", parameter, value), + }) + } + ParameterStatus { parameter, value } => { + debug!("Parameter {} = {}", parameter, value) + } val => return Ok(val) } } } - fn handle_auth(&mut self, user: PostgresUserInfo) - -> Result<(), PostgresConnectError> { + fn handle_auth(&mut self, user: PostgresUserInfo) -> Result<(), PostgresConnectError> { match try_pg_conn!(self.read_message()) { AuthenticationOk => return Ok(()), AuthenticationCleartextPassword => { @@ -506,8 +502,7 @@ impl InnerPostgresConnection { | AuthenticationSCMCredential | AuthenticationGSS | AuthenticationSSPI => return Err(UnsupportedAuthentication), - ErrorResponse { fields } => - return Err(PgConnectDbError(PostgresDbError::new(fields))), + ErrorResponse { fields } => return Err(PgConnectDbError(PostgresDbError::new(fields))), _ => { self.desynchronized = true; return Err(PgConnectBadResponse); @@ -516,8 +511,7 @@ impl InnerPostgresConnection { match try_pg_conn!(self.read_message()) { AuthenticationOk => Ok(()), - ErrorResponse { fields } => - Err(PgConnectDbError(PostgresDbError::new(fields))), + ErrorResponse { fields } => Err(PgConnectDbError(PostgresDbError::new(fields))), _ => { self.desynchronized = true; return Err(PgConnectBadResponse); @@ -526,12 +520,12 @@ impl InnerPostgresConnection { } fn set_notice_handler(&mut self, handler: Box) - -> Box { + -> Box { mem::replace(&mut self.notice_handler, handler) } fn prepare<'a>(&mut self, query: &str, conn: &'a PostgresConnection) - -> PostgresResult> { + -> PostgresResult> { let stmt_name = format!("s{}", self.next_stmt_id); self.next_stmt_id += 1; @@ -557,20 +551,22 @@ impl InnerPostgresConnection { } let mut param_types: Vec = match try_pg!(self.read_message()) { - ParameterDescription { types } => - types.iter().map(|ty| PostgresType::from_oid(*ty)).collect(), + ParameterDescription { types } => { + types.iter().map(|ty| PostgresType::from_oid(*ty)).collect() + } _ => bad_response!(self), }; let mut result_desc: Vec = match try_pg!(self.read_message()) { - RowDescription { descriptions } => + RowDescription { descriptions } => { descriptions.move_iter().map(|desc| { let RowDescriptionEntry { name, type_oid, .. } = desc; ResultDescription { name: name, ty: PostgresType::from_oid(type_oid) } - }).collect(), + }).collect() + } NoData => vec![], _ => bad_response!(self) }; @@ -592,14 +588,14 @@ impl InnerPostgresConnection { } fn set_type_names<'a, I: Iterator<&'a mut PostgresType>>(&mut self, mut it: I) - -> PostgresResult<()> { + -> PostgresResult<()> { for ty in it { match *ty { - PgUnknownType { oid, ref mut name } => - *name = try!(self.get_type_name(oid)), + PgUnknownType { oid, ref mut name } => *name = try!(self.get_type_name(oid)), _ => {} } } + Ok(()) } @@ -721,8 +717,7 @@ impl PostgresConnection { /// let maybe_conn = PostgresConnection::connect(params, &NoSsl); /// ``` pub fn connect(params: T, ssl: &SslMode) - -> Result { + -> Result { InnerPostgresConnection::connect(params, ssl).map(|conn| { PostgresConnection { conn: RefCell::new(conn) } }) @@ -730,7 +725,7 @@ impl PostgresConnection { /// Sets the notice handler for the connection, returning the old handler. pub fn set_notice_handler(&self, handler: Box) - -> Box { + -> Box { self.conn.borrow_mut().set_notice_handler(handler) } @@ -762,8 +757,7 @@ impl PostgresConnection { /// Ok(stmt) => stmt, /// Err(err) => fail!("Error preparing statement: {}", err) /// }; - pub fn prepare<'a>(&'a self, query: &str) - -> PostgresResult> { + pub fn prepare<'a>(&'a self, query: &str) -> PostgresResult> { let mut conn = self.conn.borrow_mut(); if conn.trans_depth != 0 { return Err(PgWrongTransaction); @@ -796,8 +790,7 @@ impl PostgresConnection { /// # Ok(()) /// # } /// ``` - pub fn transaction<'a>(&'a self) - -> PostgresResult> { + pub fn transaction<'a>(&'a self) -> PostgresResult> { check_desync!(self); if self.conn.borrow().trans_depth != 0 { return Err(PgWrongTransaction); @@ -818,8 +811,7 @@ impl PostgresConnection { /// or execution of the statement. /// /// On success, returns the number of rows modified or 0 if not applicable. - pub fn execute(&self, query: &str, params: &[&ToSql]) - -> PostgresResult { + pub fn execute(&self, query: &str, params: &[&ToSql]) -> PostgresResult { self.prepare(query).and_then(|stmt| stmt.execute(params)) } @@ -898,8 +890,7 @@ impl PostgresConnection { self.conn.borrow().canary() } - fn quick_query(&self, query: &str) - -> PostgresResult>>> { + fn quick_query(&self, query: &str) -> PostgresResult>>> { self.conn.borrow_mut().quick_query(query) } @@ -959,8 +950,7 @@ impl<'conn> PostgresTransaction<'conn> { } /// Like `PostgresConnection::prepare`. - pub fn prepare<'a>(&'a self, query: &str) - -> PostgresResult> { + pub fn prepare<'a>(&'a self, query: &str) -> PostgresResult> { if self.conn.conn.borrow().trans_depth != self.depth { return Err(PgWrongTransaction); } @@ -968,8 +958,7 @@ impl<'conn> PostgresTransaction<'conn> { } /// Like `PostgresConnection::execute`. - pub fn execute(&self, query: &str, params: &[&ToSql]) - -> PostgresResult { + pub fn execute(&self, query: &str, params: &[&ToSql]) -> PostgresResult { self.prepare(query).and_then(|s| s.execute(params)) } @@ -983,8 +972,7 @@ impl<'conn> PostgresTransaction<'conn> { } /// Like `PostgresConnection::transaction`. - pub fn transaction<'a>(&'a self) - -> PostgresResult> { + pub fn transaction<'a>(&'a self) -> PostgresResult> { check_desync!(self.conn); if self.conn.conn.borrow().trans_depth != self.depth { return Err(PgWrongTransaction); @@ -1010,8 +998,7 @@ impl<'conn> PostgresTransaction<'conn> { stmt: &'stmt PostgresStatement, params: &[&ToSql], row_limit: i32) - -> PostgresResult> { + -> PostgresResult> { if self.conn as *const _ != stmt.conn as *const _ { return Err(PgWrongConnection); } @@ -1097,7 +1084,7 @@ impl<'conn> PostgresStatement<'conn> { } fn inner_execute(&self, portal_name: &str, row_limit: i32, params: &[&ToSql]) - -> PostgresResult<()> { + -> PostgresResult<()> { if self.param_types.len() != params.len() { return Err(PgWrongParamCount { expected: self.param_types.len(), @@ -1142,7 +1129,7 @@ impl<'conn> PostgresStatement<'conn> { } fn lazy_query<'a>(&'a self, row_limit: i32, params: &[&ToSql]) - -> PostgresResult> { + -> PostgresResult> { let id = self.next_portal_id.get(); self.next_portal_id.set(id + 1); let portal_name = format!("{}p{}", self.name, id); @@ -1239,8 +1226,7 @@ impl<'conn> PostgresStatement<'conn> { /// println!("foo: {}", foo); /// } /// ``` - pub fn query<'a>(&'a self, params: &[&ToSql]) - -> PostgresResult> { + pub fn query<'a>(&'a self, params: &[&ToSql]) -> PostgresResult> { check_desync!(self.conn); self.lazy_query(0, params) } @@ -1308,8 +1294,7 @@ impl<'stmt> PostgresRows<'stmt> { fn read_rows(&mut self) -> PostgresResult<()> { loop { match try_pg!(self.stmt.conn.read_message()) { - EmptyQueryResponse | - CommandComplete { .. } => { + EmptyQueryResponse | CommandComplete { .. } => { self.more_rows = false; break; }, diff --git a/tests/test.rs b/tests/test.rs index 76be15c0..cf65eb97 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -95,8 +95,7 @@ fn test_unix_connection() { fail!("can't test connect_unix; unix_socket_directories is empty"); } - let unix_socket_directory = unix_socket_directories.as_slice() - .split(',').next().unwrap(); + let unix_socket_directory = unix_socket_directories.as_slice() .split(',').next().unwrap(); let url = format!("postgres://postgres@{}", url::encode_component(unix_socket_directory)); let conn = or_fail!(PostgresConnection::connect(url.as_slice(), &NoSsl));