@@ -61,6 +61,32 @@ use raw::Slice as RawSlice;
61
61
/// Extension methods for immutable slices.
62
62
#[ unstable = "may merge with other traits; region parameter may disappear" ]
63
63
pub trait ImmutableSlice < ' a , T > {
64
+ /// Returns a subslice spanning the interval [`start`, `end`).
65
+ ///
66
+ /// Fails when the end of the new slice lies beyond the end of the
67
+ /// original slice (i.e. when `end > self.len()`) or when `start > end`.
68
+ ///
69
+ /// Slicing with `start` equal to `end` yields an empty slice.
70
+ #[ unstable = "waiting on final error conventions" ]
71
+ //fn slice(&self, start: uint, end: uint) -> &'a [T];
72
+
73
+ /// Returns a subslice from `start` to the end of the slice.
74
+ ///
75
+ /// Fails when `start` is strictly greater than the length of the original slice.
76
+ ///
77
+ /// Slicing from `self.len()` yields an empty slice.
78
+ #[ unstable = "waiting on final error conventions" ]
79
+ // TODO
80
+ //fn slice_from(&self, start: uint) -> &'a [T];
81
+
82
+ /// Returns a subslice from the start of the slice to `end`.
83
+ ///
84
+ /// Fails when `end` is strictly greater than the length of the original slice.
85
+ ///
86
+ /// Slicing to `0` yields an empty slice.
87
+ #[ unstable = "waiting on final error conventions" ]
88
+ //fn slice_to(&self, end: uint) -> &'a [T];
89
+
64
90
/// Divides one slice into two at an index.
65
91
///
66
92
/// The first will contain all indices from `[0, mid)` (excluding
@@ -418,35 +444,6 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
418
444
}
419
445
}
420
446
421
- #[ cfg( not( stage0) ) ]
422
- impl < T > ops:: Slice < uint , [ T ] > for [ T ] {
423
- #[ inline]
424
- fn as_slice < ' a > ( & ' a self ) -> & ' a [ T ] {
425
- self
426
- }
427
-
428
- #[ inline]
429
- fn slice_from < ' a > ( & ' a self , start : & uint ) -> & ' a [ T ] {
430
- self . slice ( start, & self . len ( ) )
431
- }
432
-
433
- #[ inline]
434
- fn slice_to < ' a > ( & ' a self , end : & uint ) -> & ' a [ T ] {
435
- self . slice ( & 0 , end)
436
- }
437
- #[ inline]
438
- fn slice < ' a > ( & ' a self , start : & uint , end : & uint ) -> & ' a [ T ] {
439
- assert ! ( * start <= * end) ;
440
- assert ! ( * end <= self . len( ) ) ;
441
- unsafe {
442
- transmute ( RawSlice {
443
- data : self . as_ptr ( ) . offset ( * start as int ) ,
444
- len : ( * end - * start)
445
- } )
446
- }
447
- }
448
- }
449
- #[ cfg( stage0) ]
450
447
impl < T > ops:: Slice < uint , [ T ] > for [ T ] {
451
448
#[ inline]
452
449
fn as_slice_ < ' a > ( & ' a self ) -> & ' a [ T ] {
@@ -474,36 +471,7 @@ impl<T> ops::Slice<uint, [T]> for [T] {
474
471
}
475
472
}
476
473
}
477
- #[ cfg( not( stage0) ) ]
478
- impl < T > ops:: SliceMut < uint , [ T ] > for [ T ] {
479
- #[ inline]
480
- fn as_mut_slice < ' a > ( & ' a mut self ) -> & ' a mut [ T ] {
481
- self
482
- }
483
-
484
- #[ inline]
485
- fn slice_from_mut < ' a > ( & ' a mut self , start : & uint ) -> & ' a mut [ T ] {
486
- let len = & self . len ( ) ;
487
- self . slice_mut ( start, len)
488
- }
489
474
490
- #[ inline]
491
- fn slice_to_mut < ' a > ( & ' a mut self , end : & uint ) -> & ' a mut [ T ] {
492
- self . slice_mut ( & 0 , end)
493
- }
494
- #[ inline]
495
- fn slice_mut < ' a > ( & ' a mut self , start : & uint , end : & uint ) -> & ' a mut [ T ] {
496
- assert ! ( * start <= * end) ;
497
- assert ! ( * end <= self . len( ) ) ;
498
- unsafe {
499
- transmute ( RawSlice {
500
- data : self . as_ptr ( ) . offset ( * start as int ) ,
501
- len : ( * end - * start)
502
- } )
503
- }
504
- }
505
- }
506
- #[ cfg( stage0) ]
507
475
impl < T > ops:: SliceMut < uint , [ T ] > for [ T ] {
508
476
#[ inline]
509
477
fn as_mut_slice_ < ' a > ( & ' a mut self ) -> & ' a mut [ T ] {
@@ -546,6 +514,49 @@ pub trait MutableSlice<'a, T> {
546
514
#[ deprecated = "use slicing syntax" ]
547
515
fn as_mut_slice ( self ) -> & ' a mut [ T ] ;
548
516
517
+ /// Deprecated: use `slice_mut`.
518
+ #[ deprecated = "use slicing syntax" ]
519
+ //fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] {
520
+ // self[mut start..end]
521
+ //}
522
+
523
+ /// Returns a mutable subslice spanning the interval [`start`, `end`).
524
+ ///
525
+ /// Fails when the end of the new slice lies beyond the end of the
526
+ /// original slice (i.e. when `end > self.len()`) or when `start > end`.
527
+ ///
528
+ /// Slicing with `start` equal to `end` yields an empty slice.
529
+ #[ unstable = "waiting on final error conventions" ]
530
+ //fn slice_mut(self, start: uint, end: uint) -> &'a mut [T];
531
+
532
+ /// Deprecated: use `slicing syntax`.
533
+ #[ deprecated = "use slicing syntax" ]
534
+ //fn mut_slice_from(self, start: uint) -> &'a mut [T] {
535
+ // self[mut start..]
536
+ //}
537
+
538
+ /// Returns a mutable subslice from `start` to the end of the slice.
539
+ ///
540
+ /// Fails when `start` is strictly greater than the length of the original slice.
541
+ ///
542
+ /// Slicing from `self.len()` yields an empty slice.
543
+ #[ unstable = "waiting on final error conventions" ]
544
+ //fn slice_from_mut(self, start: uint) -> &'a mut [T];
545
+
546
+ /// Deprecated: use `slicing syntax`.
547
+ #[ deprecated = "use slicing syntax" ]
548
+ //fn mut_slice_to(self, end: uint) -> &'a mut [T] {
549
+ // self[mut ..end]
550
+ //}
551
+
552
+ /// Returns a mutable subslice from the start of the slice to `end`.
553
+ ///
554
+ /// Fails when `end` is strictly greater than the length of the original slice.
555
+ ///
556
+ /// Slicing to `0` yields an empty slice.
557
+ #[ unstable = "waiting on final error conventions" ]
558
+ //fn slice_to_mut(self, end: uint) -> &'a mut [T];
559
+
549
560
/// Deprecated: use `iter_mut`.
550
561
#[ deprecated = "use iter_mut" ]
551
562
fn mut_iter ( self ) -> MutItems < ' a , T > {
0 commit comments