Skip to content

Commit f7c0038

Browse files
committed
Formatting cleanup
1 parent c577e46 commit f7c0038

2 files changed

Lines changed: 44 additions & 60 deletions

File tree

src/lib.rs

Lines changed: 43 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,17 @@ pub struct PostgresConnectParams {
192192
/// `PostgresConnectParams`.
193193
pub trait IntoConnectParams {
194194
/// Converts the value of `self` into a `PostgresConnectParams`.
195-
fn into_connect_params(self) -> Result<PostgresConnectParams,
196-
PostgresConnectError>;
195+
fn into_connect_params(self) -> Result<PostgresConnectParams, PostgresConnectError>;
197196
}
198197

199198
impl IntoConnectParams for PostgresConnectParams {
200-
fn into_connect_params(self) -> Result<PostgresConnectParams,
201-
PostgresConnectError> {
199+
fn into_connect_params(self) -> Result<PostgresConnectParams, PostgresConnectError> {
202200
Ok(self)
203201
}
204202
}
205203

206204
impl<'a> IntoConnectParams for &'a str {
207-
fn into_connect_params(self) -> Result<PostgresConnectParams,
208-
PostgresConnectError> {
205+
fn into_connect_params(self) -> Result<PostgresConnectParams, PostgresConnectError> {
209206
match Url::parse(self) {
210207
Ok(url) => url.into_connect_params(),
211208
Err(err) => return Err(InvalidUrl(err)),
@@ -214,8 +211,7 @@ impl<'a> IntoConnectParams for &'a str {
214211
}
215212

216213
impl IntoConnectParams for Url {
217-
fn into_connect_params(self) -> Result<PostgresConnectParams,
218-
PostgresConnectError> {
214+
fn into_connect_params(self) -> Result<PostgresConnectParams, PostgresConnectError> {
219215
let Url {
220216
host,
221217
port,
@@ -336,8 +332,7 @@ pub struct PostgresCancelData {
336332
/// # let _ =
337333
/// postgres::cancel_query(url, &NoSsl, cancel_data);
338334
/// ```
339-
pub fn cancel_query<T: IntoConnectParams>(params: T, ssl: &SslMode,
340-
data: PostgresCancelData)
335+
pub fn cancel_query<T: IntoConnectParams>(params: T, ssl: &SslMode, data: PostgresCancelData)
341336
-> Result<(), PostgresConnectError> {
342337
let params = try!(params.into_connect_params());
343338

@@ -379,8 +374,7 @@ impl Drop for InnerPostgresConnection {
379374

380375
impl InnerPostgresConnection {
381376
fn connect<T: IntoConnectParams>(params: T, ssl: &SslMode)
382-
-> Result<InnerPostgresConnection,
383-
PostgresConnectError> {
377+
-> Result<InnerPostgresConnection, PostgresConnectError> {
384378
let params = try!(params.into_connect_params());
385379
let stream = try!(io::initialize_stream(&params, ssl));
386380

@@ -456,23 +450,25 @@ impl InnerPostgresConnection {
456450
debug_assert!(!self.desynchronized);
457451
loop {
458452
match try_desync!(self, self.stream.read_message()) {
459-
NoticeResponse { fields } =>
460-
self.notice_handler.handle(PostgresDbError::new(fields)),
461-
NotificationResponse { pid, channel, payload } =>
453+
NoticeResponse { fields } => {
454+
self.notice_handler.handle(PostgresDbError::new(fields))
455+
}
456+
NotificationResponse { pid, channel, payload } => {
462457
self.notifications.push(PostgresNotification {
463458
pid: pid,
464459
channel: channel,
465460
payload: payload
466-
}),
467-
ParameterStatus { parameter, value } =>
468-
debug!("Parameter {} = {}", parameter, value),
461+
})
462+
}
463+
ParameterStatus { parameter, value } => {
464+
debug!("Parameter {} = {}", parameter, value)
465+
}
469466
val => return Ok(val)
470467
}
471468
}
472469
}
473470

474-
fn handle_auth(&mut self, user: PostgresUserInfo)
475-
-> Result<(), PostgresConnectError> {
471+
fn handle_auth(&mut self, user: PostgresUserInfo) -> Result<(), PostgresConnectError> {
476472
match try_pg_conn!(self.read_message()) {
477473
AuthenticationOk => return Ok(()),
478474
AuthenticationCleartextPassword => {
@@ -506,8 +502,7 @@ impl InnerPostgresConnection {
506502
| AuthenticationSCMCredential
507503
| AuthenticationGSS
508504
| AuthenticationSSPI => return Err(UnsupportedAuthentication),
509-
ErrorResponse { fields } =>
510-
return Err(PgConnectDbError(PostgresDbError::new(fields))),
505+
ErrorResponse { fields } => return Err(PgConnectDbError(PostgresDbError::new(fields))),
511506
_ => {
512507
self.desynchronized = true;
513508
return Err(PgConnectBadResponse);
@@ -516,8 +511,7 @@ impl InnerPostgresConnection {
516511

517512
match try_pg_conn!(self.read_message()) {
518513
AuthenticationOk => Ok(()),
519-
ErrorResponse { fields } =>
520-
Err(PgConnectDbError(PostgresDbError::new(fields))),
514+
ErrorResponse { fields } => Err(PgConnectDbError(PostgresDbError::new(fields))),
521515
_ => {
522516
self.desynchronized = true;
523517
return Err(PgConnectBadResponse);
@@ -526,12 +520,12 @@ impl InnerPostgresConnection {
526520
}
527521

528522
fn set_notice_handler(&mut self, handler: Box<PostgresNoticeHandler+Send>)
529-
-> Box<PostgresNoticeHandler+Send> {
523+
-> Box<PostgresNoticeHandler+Send> {
530524
mem::replace(&mut self.notice_handler, handler)
531525
}
532526

533527
fn prepare<'a>(&mut self, query: &str, conn: &'a PostgresConnection)
534-
-> PostgresResult<PostgresStatement<'a>> {
528+
-> PostgresResult<PostgresStatement<'a>> {
535529
let stmt_name = format!("s{}", self.next_stmt_id);
536530
self.next_stmt_id += 1;
537531

@@ -557,20 +551,22 @@ impl InnerPostgresConnection {
557551
}
558552

559553
let mut param_types: Vec<PostgresType> = match try_pg!(self.read_message()) {
560-
ParameterDescription { types } =>
561-
types.iter().map(|ty| PostgresType::from_oid(*ty)).collect(),
554+
ParameterDescription { types } => {
555+
types.iter().map(|ty| PostgresType::from_oid(*ty)).collect()
556+
}
562557
_ => bad_response!(self),
563558
};
564559

565560
let mut result_desc: Vec<ResultDescription> = match try_pg!(self.read_message()) {
566-
RowDescription { descriptions } =>
561+
RowDescription { descriptions } => {
567562
descriptions.move_iter().map(|desc| {
568563
let RowDescriptionEntry { name, type_oid, .. } = desc;
569564
ResultDescription {
570565
name: name,
571566
ty: PostgresType::from_oid(type_oid)
572567
}
573-
}).collect(),
568+
}).collect()
569+
}
574570
NoData => vec![],
575571
_ => bad_response!(self)
576572
};
@@ -592,14 +588,14 @@ impl InnerPostgresConnection {
592588
}
593589

594590
fn set_type_names<'a, I: Iterator<&'a mut PostgresType>>(&mut self, mut it: I)
595-
-> PostgresResult<()> {
591+
-> PostgresResult<()> {
596592
for ty in it {
597593
match *ty {
598-
PgUnknownType { oid, ref mut name } =>
599-
*name = try!(self.get_type_name(oid)),
594+
PgUnknownType { oid, ref mut name } => *name = try!(self.get_type_name(oid)),
600595
_ => {}
601596
}
602597
}
598+
603599
Ok(())
604600
}
605601

@@ -721,16 +717,15 @@ impl PostgresConnection {
721717
/// let maybe_conn = PostgresConnection::connect(params, &NoSsl);
722718
/// ```
723719
pub fn connect<T: IntoConnectParams>(params: T, ssl: &SslMode)
724-
-> Result<PostgresConnection,
725-
PostgresConnectError> {
720+
-> Result<PostgresConnection, PostgresConnectError> {
726721
InnerPostgresConnection::connect(params, ssl).map(|conn| {
727722
PostgresConnection { conn: RefCell::new(conn) }
728723
})
729724
}
730725

731726
/// Sets the notice handler for the connection, returning the old handler.
732727
pub fn set_notice_handler(&self, handler: Box<PostgresNoticeHandler+Send>)
733-
-> Box<PostgresNoticeHandler+Send> {
728+
-> Box<PostgresNoticeHandler+Send> {
734729
self.conn.borrow_mut().set_notice_handler(handler)
735730
}
736731

@@ -762,8 +757,7 @@ impl PostgresConnection {
762757
/// Ok(stmt) => stmt,
763758
/// Err(err) => fail!("Error preparing statement: {}", err)
764759
/// };
765-
pub fn prepare<'a>(&'a self, query: &str)
766-
-> PostgresResult<PostgresStatement<'a>> {
760+
pub fn prepare<'a>(&'a self, query: &str) -> PostgresResult<PostgresStatement<'a>> {
767761
let mut conn = self.conn.borrow_mut();
768762
if conn.trans_depth != 0 {
769763
return Err(PgWrongTransaction);
@@ -796,8 +790,7 @@ impl PostgresConnection {
796790
/// # Ok(())
797791
/// # }
798792
/// ```
799-
pub fn transaction<'a>(&'a self)
800-
-> PostgresResult<PostgresTransaction<'a>> {
793+
pub fn transaction<'a>(&'a self) -> PostgresResult<PostgresTransaction<'a>> {
801794
check_desync!(self);
802795
if self.conn.borrow().trans_depth != 0 {
803796
return Err(PgWrongTransaction);
@@ -818,8 +811,7 @@ impl PostgresConnection {
818811
/// or execution of the statement.
819812
///
820813
/// On success, returns the number of rows modified or 0 if not applicable.
821-
pub fn execute(&self, query: &str, params: &[&ToSql])
822-
-> PostgresResult<uint> {
814+
pub fn execute(&self, query: &str, params: &[&ToSql]) -> PostgresResult<uint> {
823815
self.prepare(query).and_then(|stmt| stmt.execute(params))
824816
}
825817

@@ -898,8 +890,7 @@ impl PostgresConnection {
898890
self.conn.borrow().canary()
899891
}
900892

901-
fn quick_query(&self, query: &str)
902-
-> PostgresResult<Vec<Vec<Option<String>>>> {
893+
fn quick_query(&self, query: &str) -> PostgresResult<Vec<Vec<Option<String>>>> {
903894
self.conn.borrow_mut().quick_query(query)
904895
}
905896

@@ -959,17 +950,15 @@ impl<'conn> PostgresTransaction<'conn> {
959950
}
960951

961952
/// Like `PostgresConnection::prepare`.
962-
pub fn prepare<'a>(&'a self, query: &str)
963-
-> PostgresResult<PostgresStatement<'a>> {
953+
pub fn prepare<'a>(&'a self, query: &str) -> PostgresResult<PostgresStatement<'a>> {
964954
if self.conn.conn.borrow().trans_depth != self.depth {
965955
return Err(PgWrongTransaction);
966956
}
967957
self.conn.conn.borrow_mut().prepare(query, self.conn)
968958
}
969959

970960
/// Like `PostgresConnection::execute`.
971-
pub fn execute(&self, query: &str, params: &[&ToSql])
972-
-> PostgresResult<uint> {
961+
pub fn execute(&self, query: &str, params: &[&ToSql]) -> PostgresResult<uint> {
973962
self.prepare(query).and_then(|s| s.execute(params))
974963
}
975964

@@ -983,8 +972,7 @@ impl<'conn> PostgresTransaction<'conn> {
983972
}
984973

985974
/// Like `PostgresConnection::transaction`.
986-
pub fn transaction<'a>(&'a self)
987-
-> PostgresResult<PostgresTransaction<'a>> {
975+
pub fn transaction<'a>(&'a self) -> PostgresResult<PostgresTransaction<'a>> {
988976
check_desync!(self.conn);
989977
if self.conn.conn.borrow().trans_depth != self.depth {
990978
return Err(PgWrongTransaction);
@@ -1010,8 +998,7 @@ impl<'conn> PostgresTransaction<'conn> {
1010998
stmt: &'stmt PostgresStatement,
1011999
params: &[&ToSql],
10121000
row_limit: i32)
1013-
-> PostgresResult<PostgresLazyRows
1014-
<'trans, 'stmt>> {
1001+
-> PostgresResult<PostgresLazyRows <'trans, 'stmt>> {
10151002
if self.conn as *const _ != stmt.conn as *const _ {
10161003
return Err(PgWrongConnection);
10171004
}
@@ -1097,7 +1084,7 @@ impl<'conn> PostgresStatement<'conn> {
10971084
}
10981085

10991086
fn inner_execute(&self, portal_name: &str, row_limit: i32, params: &[&ToSql])
1100-
-> PostgresResult<()> {
1087+
-> PostgresResult<()> {
11011088
if self.param_types.len() != params.len() {
11021089
return Err(PgWrongParamCount {
11031090
expected: self.param_types.len(),
@@ -1142,7 +1129,7 @@ impl<'conn> PostgresStatement<'conn> {
11421129
}
11431130

11441131
fn lazy_query<'a>(&'a self, row_limit: i32, params: &[&ToSql])
1145-
-> PostgresResult<PostgresRows<'a>> {
1132+
-> PostgresResult<PostgresRows<'a>> {
11461133
let id = self.next_portal_id.get();
11471134
self.next_portal_id.set(id + 1);
11481135
let portal_name = format!("{}p{}", self.name, id);
@@ -1239,8 +1226,7 @@ impl<'conn> PostgresStatement<'conn> {
12391226
/// println!("foo: {}", foo);
12401227
/// }
12411228
/// ```
1242-
pub fn query<'a>(&'a self, params: &[&ToSql])
1243-
-> PostgresResult<PostgresRows<'a>> {
1229+
pub fn query<'a>(&'a self, params: &[&ToSql]) -> PostgresResult<PostgresRows<'a>> {
12441230
check_desync!(self.conn);
12451231
self.lazy_query(0, params)
12461232
}
@@ -1308,8 +1294,7 @@ impl<'stmt> PostgresRows<'stmt> {
13081294
fn read_rows(&mut self) -> PostgresResult<()> {
13091295
loop {
13101296
match try_pg!(self.stmt.conn.read_message()) {
1311-
EmptyQueryResponse |
1312-
CommandComplete { .. } => {
1297+
EmptyQueryResponse | CommandComplete { .. } => {
13131298
self.more_rows = false;
13141299
break;
13151300
},

tests/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ fn test_unix_connection() {
9595
fail!("can't test connect_unix; unix_socket_directories is empty");
9696
}
9797

98-
let unix_socket_directory = unix_socket_directories.as_slice()
99-
.split(',').next().unwrap();
98+
let unix_socket_directory = unix_socket_directories.as_slice() .split(',').next().unwrap();
10099

101100
let url = format!("postgres://postgres@{}", url::encode_component(unix_socket_directory));
102101
let conn = or_fail!(PostgresConnection::connect(url.as_slice(), &NoSsl));

0 commit comments

Comments
 (0)