Skip to content

Commit 3181d39

Browse files
committed
Use more idiomatic names for row iterators
1 parent b2c7e08 commit 3181d39

2 files changed

Lines changed: 27 additions & 33 deletions

File tree

src/lib.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -981,15 +981,14 @@ impl<'conn> PostgresTransaction<'conn> {
981981
stmt: &'stmt PostgresStatement,
982982
params: &[&ToSql],
983983
row_limit: uint)
984-
-> Result<PostgresLazyResult<'trans,
985-
'stmt>,
984+
-> Result<PostgresLazyRows<'trans, 'stmt>,
986985
PostgresError> {
987986
if self.conn as *PostgresConnection != stmt.conn as *PostgresConnection {
988987
return Err(PgWrongConnection);
989988
}
990989
check_desync!(self.conn);
991990
stmt.lazy_query(row_limit, params).map(|result| {
992-
PostgresLazyResult {
991+
PostgresLazyRows {
993992
trans: self,
994993
result: result
995994
}
@@ -1087,14 +1086,14 @@ impl<'conn> PostgresStatement<'conn> {
10871086
}
10881087

10891088
fn lazy_query<'a>(&'a self, row_limit: uint, params: &[&ToSql])
1090-
-> Result<PostgresResult<'a>, PostgresError> {
1089+
-> Result<PostgresRows<'a>, PostgresError> {
10911090
let id = self.next_portal_id.get();
10921091
self.next_portal_id.set(id + 1);
10931092
let portal_name = format!("{}_portal_{}", self.name, id);
10941093

10951094
try!(self.inner_execute(portal_name, row_limit, params));
10961095

1097-
let mut result = PostgresResult {
1096+
let mut result = PostgresRows {
10981097
stmt: self,
10991098
name: portal_name,
11001099
data: RingBuf::new(),
@@ -1187,7 +1186,7 @@ impl<'conn> PostgresStatement<'conn> {
11871186
/// }
11881187
/// ```
11891188
pub fn query<'a>(&'a self, params: &[&ToSql])
1190-
-> Result<PostgresResult<'a>, PostgresError> {
1189+
-> Result<PostgresRows<'a>, PostgresError> {
11911190
check_desync!(self.conn);
11921191
self.lazy_query(0, params)
11931192
}
@@ -1212,7 +1211,7 @@ pub struct ResultDescription {
12121211
}
12131212

12141213
/// An iterator over the resulting rows of a query.
1215-
pub struct PostgresResult<'stmt> {
1214+
pub struct PostgresRows<'stmt> {
12161215
stmt: &'stmt PostgresStatement<'stmt>,
12171216
name: ~str,
12181217
data: RingBuf<Vec<Option<~[u8]>>>,
@@ -1222,7 +1221,7 @@ pub struct PostgresResult<'stmt> {
12221221
}
12231222

12241223
#[unsafe_destructor]
1225-
impl<'stmt> Drop for PostgresResult<'stmt> {
1224+
impl<'stmt> Drop for PostgresRows<'stmt> {
12261225
fn drop(&mut self) {
12271226
if !self.finished {
12281227
match self.finish_inner() {
@@ -1234,7 +1233,7 @@ impl<'stmt> Drop for PostgresResult<'stmt> {
12341233
}
12351234
}
12361235

1237-
impl<'stmt> PostgresResult<'stmt> {
1236+
impl<'stmt> PostgresRows<'stmt> {
12381237
fn finish_inner(&mut self) -> Result<(), PostgresError> {
12391238
check_desync!(self.stmt.conn);
12401239
try_pg!(self.stmt.conn.write_messages([
@@ -1286,11 +1285,11 @@ impl<'stmt> PostgresResult<'stmt> {
12861285
}
12871286
}
12881287

1289-
impl<'stmt> PostgresResult<'stmt> {
1290-
/// Consumes the `PostgresResult`, cleaning up associated state.
1288+
impl<'stmt> PostgresRows<'stmt> {
1289+
/// Consumes the `PostgresRows`, cleaning up associated state.
12911290
///
1292-
/// Functionally identical to the `Drop` implementation on
1293-
/// `PostgresResult` except that it returns any error to the caller.
1291+
/// Functionally identical to the `Drop` implementation on `PostgresRows`
1292+
/// except that it returns any error to the caller.
12941293
pub fn finish(mut self) -> Result<(), PostgresError> {
12951294
self.finished = true;
12961295
self.finish_inner()
@@ -1314,7 +1313,7 @@ impl<'stmt> PostgresResult<'stmt> {
13141313
}
13151314
}
13161315

1317-
impl<'stmt> Iterator<PostgresRow<'stmt>> for PostgresResult<'stmt> {
1316+
impl<'stmt> Iterator<PostgresRow<'stmt>> for PostgresRows<'stmt> {
13181317
fn next(&mut self) -> Option<PostgresRow<'stmt>> {
13191318
// we'll never hit the network on a non-lazy result
13201319
self.try_next().map(|r| r.unwrap())
@@ -1363,7 +1362,8 @@ impl<'stmt> Container for PostgresRow<'stmt> {
13631362
}
13641363
}
13651364

1366-
impl<'stmt, I: RowIndex+Clone+fmt::Show, T: FromSql> Index<I, T> for PostgresRow<'stmt> {
1365+
impl<'stmt, I: RowIndex+Clone+fmt::Show, T: FromSql> Index<I, T>
1366+
for PostgresRow<'stmt> {
13671367
/// Retreives the contents of a field of the row.
13681368
///
13691369
/// A field can be accessed by the name or index of its column, though
@@ -1388,7 +1388,7 @@ impl<'stmt, I: RowIndex+Clone+fmt::Show, T: FromSql> Index<I, T> for PostgresRow
13881388
fn index(&self, idx: &I) -> T {
13891389
match self.get(idx.clone()) {
13901390
Ok(ok) => ok,
1391-
Err(err) => fail!("error retrieving row[{}]: {}", idx, err)
1391+
Err(err) => fail!("error retrieving row {}: {}", idx, err)
13921392
}
13931393
}
13941394
}
@@ -1435,20 +1435,20 @@ impl<'a> RowIndex for &'a str {
14351435
}
14361436

14371437
/// A lazily-loaded iterator over the resulting rows of a query
1438-
pub struct PostgresLazyResult<'trans, 'stmt> {
1439-
result: PostgresResult<'stmt>,
1438+
pub struct PostgresLazyRows<'trans, 'stmt> {
1439+
result: PostgresRows<'stmt>,
14401440
trans: &'trans PostgresTransaction<'trans>,
14411441
}
14421442

1443-
impl<'trans, 'stmt> PostgresLazyResult<'trans, 'stmt> {
1444-
/// Like `PostgresResult::finish`.
1443+
impl<'trans, 'stmt> PostgresLazyRows<'trans, 'stmt> {
1444+
/// Like `PostgresRows::finish`.
14451445
pub fn finish(self) -> Result<(), PostgresError> {
14461446
self.result.finish()
14471447
}
14481448
}
14491449

14501450
impl<'trans, 'stmt> Iterator<Result<PostgresRow<'stmt>, PostgresError>>
1451-
for PostgresLazyResult<'trans, 'stmt> {
1451+
for PostgresLazyRows<'trans, 'stmt> {
14521452
fn next(&mut self) -> Option<Result<PostgresRow<'stmt>, PostgresError>> {
14531453
self.result.try_next()
14541454
}

src/types/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -538,29 +538,25 @@ macro_rules! raw_to_impl(
538538
)
539539

540540
impl RawToSql for bool {
541-
fn raw_to_sql<W: Writer>(&self, w: &mut W)
542-
-> Result<(), PostgresError> {
541+
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<(), PostgresError> {
543542
Ok(try_pg!(w.write_u8(*self as u8)))
544543
}
545544
}
546545

547546
impl RawToSql for ~[u8] {
548-
fn raw_to_sql<W: Writer>(&self, w: &mut W)
549-
-> Result<(), PostgresError> {
547+
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<(), PostgresError> {
550548
Ok(try_pg!(w.write(self.as_slice())))
551549
}
552550
}
553551

554552
impl RawToSql for Vec<u8> {
555-
fn raw_to_sql<W: Writer>(&self, w: &mut W)
556-
-> Result<(), PostgresError> {
553+
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<(), PostgresError> {
557554
Ok(try_pg!(w.write(self.as_slice())))
558555
}
559556
}
560557

561558
impl RawToSql for ~str {
562-
fn raw_to_sql<W: Writer>(&self, w: &mut W)
563-
-> Result<(), PostgresError> {
559+
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<(), PostgresError> {
564560
Ok(try_pg!(w.write(self.as_bytes())))
565561
}
566562
}
@@ -573,17 +569,15 @@ raw_to_impl!(f32, write_be_f32)
573569
raw_to_impl!(f64, write_be_f64)
574570

575571
impl RawToSql for Timespec {
576-
fn raw_to_sql<W: Writer>(&self, w: &mut W)
577-
-> Result<(), PostgresError> {
572+
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<(), PostgresError> {
578573
let t = (self.sec - TIME_SEC_CONVERSION) * USEC_PER_SEC
579574
+ self.nsec as i64 / NSEC_PER_USEC;
580575
Ok(try_pg!(w.write_be_i64(t)))
581576
}
582577
}
583578

584579
impl RawToSql for Uuid {
585-
fn raw_to_sql<W: Writer>(&self, w: &mut W)
586-
-> Result<(), PostgresError> {
580+
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<(), PostgresError> {
587581
Ok(try_pg!(w.write(self.as_bytes())))
588582
}
589583
}

0 commit comments

Comments
 (0)