@@ -79,7 +79,7 @@ extern crate log;
79
79
extern crate phf;
80
80
extern crate postgres_protocol;
81
81
82
- use fallible_iterator:: FallibleIterator ;
82
+ use fallible_iterator:: { FallibleIterator , FromFallibleIterator } ;
83
83
use std:: cell:: { Cell , RefCell } ;
84
84
use std:: collections:: { VecDeque , HashMap } ;
85
85
use std:: fmt;
@@ -504,14 +504,7 @@ impl InnerConnection {
504
504
more_rows = true ;
505
505
break ;
506
506
}
507
- backend:: Message :: DataRow ( body) => {
508
- let mut row = RowData :: new ( ) ;
509
- let mut it = body. values ( ) ;
510
- while let Some ( value) = try!( it. next ( ) ) {
511
- row. push ( value) ;
512
- }
513
- consumer ( row) ;
514
- }
507
+ backend:: Message :: DataRow ( body) => consumer ( try!( body. values ( ) . collect ( ) ) ) ,
515
508
backend:: Message :: ErrorResponse ( body) => {
516
509
try!( self . wait_for_ready ( ) ) ;
517
510
return DbError :: new ( & mut body. fields ( ) ) ;
@@ -1338,26 +1331,32 @@ struct RowData {
1338
1331
indices : Vec < Option < Range < usize > > > ,
1339
1332
}
1340
1333
1341
- impl RowData {
1342
- fn new ( ) -> RowData {
1343
- RowData {
1334
+ impl < ' a > FromFallibleIterator < Option < & ' a [ u8 ] > > for RowData {
1335
+ fn from_fallible_iterator < I > ( mut it : I ) -> result:: Result < Self , I :: Error >
1336
+ where I : FallibleIterator < Item = Option < & ' a [ u8 ] > >
1337
+ {
1338
+ let mut row = RowData {
1344
1339
buf : vec ! [ ] ,
1345
- indices : vec ! [ ] ,
1340
+ indices : Vec :: with_capacity ( it. size_hint ( ) . 0 ) ,
1341
+ } ;
1342
+
1343
+ while let Some ( cell) = try!( it. next ( ) ) {
1344
+ let index = match cell {
1345
+ Some ( cell) => {
1346
+ let base = row. buf . len ( ) ;
1347
+ row. buf . extend_from_slice ( cell) ;
1348
+ Some ( base..row. buf . len ( ) )
1349
+ }
1350
+ None => None ,
1351
+ } ;
1352
+ row. indices . push ( index) ;
1346
1353
}
1347
- }
1348
1354
1349
- fn push ( & mut self , cell : Option < & [ u8 ] > ) {
1350
- let index = match cell {
1351
- Some ( cell) => {
1352
- let base = self . buf . len ( ) ;
1353
- self . buf . extend_from_slice ( cell) ;
1354
- Some ( base..self . buf . len ( ) )
1355
- }
1356
- None => None ,
1357
- } ;
1358
- self . indices . push ( index) ;
1355
+ Ok ( row)
1359
1356
}
1357
+ }
1360
1358
1359
+ impl RowData {
1361
1360
fn len ( & self ) -> usize {
1362
1361
self . indices . len ( )
1363
1362
}
0 commit comments