@@ -200,9 +200,8 @@ use cmp::Ordering;
200200use fmt:: { self , Debug , Display } ;
201201use marker:: Unsize ;
202202use mem;
203- use ops:: { Deref , DerefMut , CoerceUnsized , Index } ;
203+ use ops:: { Deref , DerefMut , CoerceUnsized } ;
204204use ptr;
205- use slice:: SliceIndex ;
206205
207206/// A mutable memory location.
208207///
@@ -511,9 +510,8 @@ impl<T: ?Sized> Cell<T> {
511510 ///
512511 /// let slice: &mut [i32] = &mut [1, 2, 3];
513512 /// 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( );
515514 ///
516- /// let slice_cell: &[Cell<i32>] = &cell_slice[..];
517515 /// assert_eq!(slice_cell.len(), 3);
518516 /// ```
519517 #[ inline]
@@ -548,15 +546,25 @@ impl<T: Default> Cell<T> {
548546#[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
549547impl < T : CoerceUnsized < U > , U > CoerceUnsized < Cell < U > > for Cell < T > { }
550548
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 > ] {
558566 unsafe {
559- Index :: index ( & * ( self as * const Cell < [ T ] > as * const [ Cell < T > ] ) , index )
567+ & * ( self as * const Cell < [ T ] > as * const [ Cell < T > ] )
560568 }
561569 }
562570}
0 commit comments