@@ -200,8 +200,9 @@ use cmp::Ordering;
200200use fmt:: { self , Debug , Display } ;
201201use marker:: Unsize ;
202202use mem;
203- use ops:: { Deref , DerefMut , CoerceUnsized } ;
203+ use ops:: { Deref , DerefMut , CoerceUnsized , Index } ;
204204use ptr;
205+ use slice:: SliceIndex ;
205206
206207/// A mutable memory location.
207208///
@@ -510,7 +511,7 @@ impl<T: ?Sized> Cell<T> {
510511 ///
511512 /// let slice: &mut [i32] = &mut [1, 2, 3];
512513 /// let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
513- /// assert_eq!(cell_slice.len(), 3);
514+ /// assert_eq!(cell_slice[..] .len(), 3);
514515 ///
515516 /// let slice_cell: &[Cell<i32>] = &cell_slice[..];
516517 /// assert_eq!(slice_cell.len(), 3);
@@ -548,23 +549,14 @@ impl<T: Default> Cell<T> {
548549impl < T : CoerceUnsized < U > , U > CoerceUnsized < Cell < U > > for Cell < T > { }
549550
550551#[ 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 ;
553556
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 {
566558 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 )
568560 }
569561 }
570562}
0 commit comments