@@ -1504,27 +1504,36 @@ pub trait Iterator {
1504
1504
/// assert_eq!(odd, vec![1, 3]);
1505
1505
/// ```
1506
1506
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1507
- fn partition < B , F > ( self , mut predicate : F ) -> ( B , B ) where
1507
+ fn partition < B , F > ( self , predicate : F ) -> ( B , B )
1508
+ where
1508
1509
Self : Sized ,
1509
1510
B : Default + Extend < Self :: Item > ,
1510
- F : FnMut ( & Self :: Item ) -> bool
1511
+ F : FnMut ( & Self :: Item ) -> bool ,
1511
1512
{
1512
1513
let mut left: B = Default :: default ( ) ;
1513
1514
let mut right: B = Default :: default ( ) ;
1514
- let right_ref = & mut right;
1515
1515
1516
- left. extend ( self . filter_map ( #[ inline] move |item| {
1517
- if predicate ( & item) {
1518
- Some ( item)
1519
- } else {
1520
- right_ref. extend ( Some ( item) ) ;
1521
- None
1516
+ #[ inline]
1517
+ fn extend_rhs < ' a , A , T : Extend < A > , P : FnMut ( & A ) -> bool + ' a > (
1518
+ rhs : & ' a mut T ,
1519
+ mut predicate : P ,
1520
+ ) -> impl FnMut ( A ) -> Option < A > + ' a {
1521
+ move |item| {
1522
+ if predicate ( & item) {
1523
+ Some ( item)
1524
+ } else {
1525
+ rhs. extend ( Some ( item) ) ;
1526
+ None
1527
+ }
1522
1528
}
1523
- } ) ) ;
1529
+ }
1530
+
1531
+ left. extend ( self . filter_map ( extend_rhs ( & mut right, predicate) ) ) ;
1524
1532
1525
1533
( left, right)
1526
1534
}
1527
1535
1536
+
1528
1537
/// Reorder the elements of this iterator *in-place* according to the given predicate,
1529
1538
/// such that all those that return `true` precede all those that return `false`.
1530
1539
/// Returns the number of `true` elements found.
@@ -2366,23 +2375,29 @@ pub trait Iterator {
2366
2375
/// assert_eq!(right, [2, 4]);
2367
2376
/// ```
2368
2377
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2369
- fn unzip < A , B , FromA , FromB > ( self ) -> ( FromA , FromB ) where
2378
+ fn unzip < A , B , FromA , FromB > ( self ) -> ( FromA , FromB )
2379
+ where
2370
2380
FromA : Default + Extend < A > ,
2371
2381
FromB : Default + Extend < B > ,
2372
- Self : Sized + Iterator < Item = ( A , B ) > ,
2382
+ Self : Sized + Iterator < Item = ( A , B ) > ,
2373
2383
{
2374
2384
let mut lhs = FromA :: default ( ) ;
2375
2385
let mut rhs = FromB :: default ( ) ;
2376
- let rhs_ref = & mut rhs;
2377
2386
2378
- lhs. extend ( self . map ( #[ inline] move |( a, b) | {
2379
- rhs_ref. extend ( Some ( b) ) ;
2380
- a
2381
- } ) ) ;
2387
+ #[ inline]
2388
+ fn extend_rhs < ' a , A , B , T : Extend < B > > ( rhs : & ' a mut T ) -> impl FnMut ( ( A , B ) ) -> A + ' a {
2389
+ move |( a, b) | {
2390
+ rhs. extend ( Some ( b) ) ;
2391
+ a
2392
+ }
2393
+ }
2394
+
2395
+ lhs. extend ( self . map ( extend_rhs ( & mut rhs) ) ) ;
2382
2396
2383
2397
( lhs, rhs)
2384
2398
}
2385
2399
2400
+
2386
2401
/// Creates an iterator which copies all of its elements.
2387
2402
///
2388
2403
/// This is useful when you have an iterator over `&T`, but you need an
0 commit comments