@@ -1671,6 +1671,15 @@ pub trait MutableVector<'self, T> {
1671
1671
1672
1672
fn swap( self , a: uint, b: uint) ;
1673
1673
1674
+ /**
1675
+ * Divides one `&mut` into two. The first will
1676
+ * contain all indices from `0..mid` (excluding the index `mid`
1677
+ * itself) and the second will contain all indices from
1678
+ * `mid..len` (excluding the index `len` itself).
1679
+ */
1680
+ fn mut_split( self , mid: uint) -> ( & ' self mut [ T ] ,
1681
+ & ' self mut [ T ] ) ;
1682
+
1674
1683
fn reverse( self ) ;
1675
1684
1676
1685
/**
@@ -1708,6 +1717,15 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
1708
1717
}
1709
1718
}
1710
1719
1720
+ #[ inline]
1721
+ fn mut_split( self , mid: uint) -> ( & ' self mut [ T ] , & ' self mut [ T ] ) {
1722
+ unsafe {
1723
+ let len = self . len( ) ;
1724
+ let self2: & ' self mut [ T ] = cast:: transmute_copy( & self ) ;
1725
+ ( self . mut_slice( 0 , mid) , self2. mut_slice( mid, len) )
1726
+ }
1727
+ }
1728
+
1711
1729
#[ inline]
1712
1730
fn mut_iter( self ) -> VecMutIterator <' self , T > {
1713
1731
unsafe {
@@ -3355,4 +3373,23 @@ mod tests {
3355
3373
v. push( 1 ) ;
3356
3374
v. push( 2 ) ;
3357
3375
}
3376
+
3377
+ #[ test]
3378
+ fn test_mut_split( ) {
3379
+ let mut values = [ 1u8 , 2 , 3 , 4 , 5 ] ;
3380
+ {
3381
+ let ( left, right) = values. mut_split( 2 ) ;
3382
+ assert_eq ! ( left. slice( 0 , left. len( ) ) , [ 1 , 2 ] ) ;
3383
+ for left. mut_iter( ) . advance |p| {
3384
+ * p += 1 ;
3385
+ }
3386
+
3387
+ assert_eq ! ( right. slice( 0 , right. len( ) ) , [ 3 , 4 , 5 ] ) ;
3388
+ for right. mut_iter( ) . advance |p| {
3389
+ * p += 2 ;
3390
+ }
3391
+ }
3392
+
3393
+ assert_eq ! ( values, [ 2 , 3 , 5 , 6 , 7 ] ) ;
3394
+ }
3358
3395
}
0 commit comments