@@ -200,9 +200,8 @@ 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 , Index } ;
203
+ use ops:: { Deref , DerefMut , CoerceUnsized } ;
204
204
use ptr;
205
- use slice:: SliceIndex ;
206
205
207
206
/// A mutable memory location.
208
207
///
@@ -511,9 +510,8 @@ impl<T: ?Sized> Cell<T> {
511
510
///
512
511
/// let slice: &mut [i32] = &mut [1, 2, 3];
513
512
/// let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
514
- /// assert_eq!(cell_slice[..].len(), 3 );
513
+ /// let slice_cell: &[Cell<i32>] = cell_slice.as_slice_of_cells( );
515
514
///
516
- /// let slice_cell: &[Cell<i32>] = &cell_slice[..];
517
515
/// assert_eq!(slice_cell.len(), 3);
518
516
/// ```
519
517
#[ inline]
@@ -548,15 +546,25 @@ impl<T: Default> Cell<T> {
548
546
#[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
549
547
impl < T : CoerceUnsized < U > , U > CoerceUnsized < Cell < U > > for Cell < T > { }
550
548
551
- #[ unstable( feature = "as_cell" , issue="43038" ) ]
552
- impl < T , I > Index < I > for Cell < [ T ] >
553
- where I : SliceIndex < [ Cell < T > ] >
554
- {
555
- type Output = I :: Output ;
556
-
557
- fn index ( & self , index : I ) -> & Self :: Output {
549
+ impl < T > Cell < [ T ] > {
550
+ /// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
551
+ ///
552
+ /// # Examples
553
+ ///
554
+ /// ```
555
+ /// #![feature(as_cell)]
556
+ /// use std::cell::Cell;
557
+ ///
558
+ /// let slice: &mut [i32] = &mut [1, 2, 3];
559
+ /// let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
560
+ /// let slice_cell: &[Cell<i32>] = cell_slice.as_slice_of_cells();
561
+ ///
562
+ /// assert_eq!(slice_cell.len(), 3);
563
+ /// ```
564
+ #[ unstable( feature = "as_cell" , issue="43038" ) ]
565
+ pub fn as_slice_of_cells ( & self ) -> & [ Cell < T > ] {
558
566
unsafe {
559
- Index :: index ( & * ( self as * const Cell < [ T ] > as * const [ Cell < T > ] ) , index )
567
+ & * ( self as * const Cell < [ T ] > as * const [ Cell < T > ] )
560
568
}
561
569
}
562
570
}
0 commit comments