@@ -200,8 +200,9 @@ use cmp::Ordering;
200
200
use fmt:: { self , Debug , Display } ;
201
201
use marker:: Unsize ;
202
202
use mem;
203
- use ops:: { Deref , DerefMut , CoerceUnsized } ;
203
+ use ops:: { Deref , DerefMut , CoerceUnsized , Index } ;
204
204
use ptr;
205
+ use slice:: SliceIndex ;
205
206
206
207
/// A mutable memory location.
207
208
///
@@ -510,7 +511,7 @@ impl<T: ?Sized> Cell<T> {
510
511
///
511
512
/// let slice: &mut [i32] = &mut [1, 2, 3];
512
513
/// let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
513
- /// assert_eq!(cell_slice.len(), 3);
514
+ /// assert_eq!(cell_slice[..] .len(), 3);
514
515
///
515
516
/// let slice_cell: &[Cell<i32>] = &cell_slice[..];
516
517
/// assert_eq!(slice_cell.len(), 3);
@@ -548,23 +549,14 @@ impl<T: Default> Cell<T> {
548
549
impl < T : CoerceUnsized < U > , U > CoerceUnsized < Cell < U > > for Cell < T > { }
549
550
550
551
#[ unstable( feature = "as_cell" , issue="43038" ) ]
551
- impl < T > Deref for Cell < [ T ] > {
552
- type Target = [ Cell < T > ] ;
552
+ impl < T , I > Index < I > for Cell < [ T ] >
553
+ where I : SliceIndex < [ Cell < T > ] >
554
+ {
555
+ type Output = I :: Output ;
553
556
554
- #[ inline]
555
- fn deref ( & self ) -> & [ Cell < T > ] {
556
- unsafe {
557
- & * ( self as * const Cell < [ T ] > as * const [ Cell < T > ] )
558
- }
559
- }
560
- }
561
-
562
- #[ unstable( feature = "as_cell" , issue="43038" ) ]
563
- impl < T > DerefMut for Cell < [ T ] > {
564
- #[ inline]
565
- fn deref_mut ( & mut self ) -> & mut [ Cell < T > ] {
557
+ fn index ( & self , index : I ) -> & Self :: Output {
566
558
unsafe {
567
- & mut * ( self as * mut Cell < [ T ] > as * mut [ Cell < T > ] )
559
+ Index :: index ( & * ( self as * const Cell < [ T ] > as * const [ Cell < T > ] ) , index )
568
560
}
569
561
}
570
562
}
0 commit comments