|
1 | 1 | //! Query result rows.
|
2 | 2 |
|
| 3 | +use fallible_iterator::FallibleIterator; |
| 4 | +use postgres_protocol::message::frontend; |
3 | 5 | use std::ascii::AsciiExt;
|
4 | 6 | use std::borrow::Cow;
|
5 | 7 | use std::collections::VecDeque;
|
6 | 8 | use std::fmt;
|
7 | 9 | use std::ops::Deref;
|
8 | 10 | use std::slice;
|
9 |
| -use postgres_protocol::message::frontend; |
10 | 11 |
|
11 | 12 | use {Result, SessionInfoNew, RowsNew, LazyRowsNew, StatementInternals, WrongTypeNew};
|
12 | 13 | use transaction::Transaction;
|
@@ -55,9 +56,9 @@ impl<'a> RowsNew<'a> for Rows<'a> {
|
55 | 56 | impl<'a> fmt::Debug for Rows<'a> {
|
56 | 57 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
57 | 58 | fmt.debug_struct("Rows")
|
58 |
| - .field("columns", &self.columns()) |
59 |
| - .field("rows", &self.data.len()) |
60 |
| - .finish() |
| 59 | + .field("columns", &self.columns()) |
| 60 | + .field("rows", &self.data.len()) |
| 61 | + .finish() |
61 | 62 | }
|
62 | 63 | }
|
63 | 64 |
|
@@ -152,8 +153,8 @@ pub struct Row<'a> {
|
152 | 153 | impl<'a> fmt::Debug for Row<'a> {
|
153 | 154 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
154 | 155 | fmt.debug_struct("Row")
|
155 |
| - .field("statement", self.stmt) |
156 |
| - .finish() |
| 156 | + .field("statement", self.stmt) |
| 157 | + .finish() |
157 | 158 | }
|
158 | 159 | }
|
159 | 160 |
|
@@ -332,11 +333,11 @@ impl<'a, 'b> Drop for LazyRows<'a, 'b> {
|
332 | 333 | impl<'a, 'b> fmt::Debug for LazyRows<'a, 'b> {
|
333 | 334 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
334 | 335 | fmt.debug_struct("LazyRows")
|
335 |
| - .field("name", &self.name) |
336 |
| - .field("row_limit", &self.row_limit) |
337 |
| - .field("remaining_rows", &self.data.len()) |
338 |
| - .field("more_rows", &self.more_rows) |
339 |
| - .finish() |
| 336 | + .field("name", &self.name) |
| 337 | + .field("row_limit", &self.row_limit) |
| 338 | + .field("remaining_rows", &self.data.len()) |
| 339 | + .field("more_rows", &self.more_rows) |
| 340 | + .finish() |
340 | 341 | }
|
341 | 342 | }
|
342 | 343 |
|
@@ -373,22 +374,25 @@ impl<'trans, 'stmt> LazyRows<'trans, 'stmt> {
|
373 | 374 | }
|
374 | 375 | }
|
375 | 376 |
|
376 |
| -impl<'trans, 'stmt> Iterator for LazyRows<'trans, 'stmt> { |
377 |
| - type Item = Result<Row<'stmt>>; |
| 377 | +impl<'trans, 'stmt> FallibleIterator for LazyRows<'trans, 'stmt> { |
| 378 | + type Item = Row<'stmt>; |
| 379 | + type Error = Error; |
378 | 380 |
|
379 |
| - fn next(&mut self) -> Option<Result<Row<'stmt>>> { |
| 381 | + fn next(&mut self) -> Result<Option<Row<'stmt>>> { |
380 | 382 | if self.data.is_empty() && self.more_rows {
|
381 |
| - if let Err(err) = self.execute() { |
382 |
| - return Some(Err(err)); |
383 |
| - } |
| 383 | + try!(self.execute()); |
384 | 384 | }
|
385 | 385 |
|
386 |
| - self.data.pop_front().map(|r| { |
387 |
| - Ok(Row { |
388 |
| - stmt: self.stmt, |
389 |
| - data: Cow::Owned(r), |
390 |
| - }) |
391 |
| - }) |
| 386 | + let row = self.data |
| 387 | + .pop_front() |
| 388 | + .map(|r| { |
| 389 | + Row { |
| 390 | + stmt: self.stmt, |
| 391 | + data: Cow::Owned(r), |
| 392 | + } |
| 393 | + }); |
| 394 | + |
| 395 | + Ok(row) |
392 | 396 | }
|
393 | 397 |
|
394 | 398 | fn size_hint(&self) -> (usize, Option<usize>) {
|
|
0 commit comments