diff options
| author | F001 <changchun.fan@qq.com> | 2018-07-23 19:20:50 +0800 |
|---|---|---|
| committer | f001 <changchun.fan@qq.com> | 2018-07-23 20:58:40 +0800 |
| commit | 489101cc45d21d3909a728d16864e26599c12bee (patch) | |
| tree | eff4752bf9ada9a3c1513174b9656a76e5c7a880 /src/libcore | |
| parent | 8812c6bae92d1a8e3a255d3eacd40cd9b65bb7f6 (diff) | |
| download | rust-489101cc45d21d3909a728d16864e26599c12bee.tar.gz rust-489101cc45d21d3909a728d16864e26599c12bee.zip | |
use inherent method instead
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/cell.rs | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 8a0f499b598..b6087628ea6 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -200,9 +200,8 @@ use cmp::Ordering; use fmt::{self, Debug, Display}; use marker::Unsize; use mem; -use ops::{Deref, DerefMut, CoerceUnsized, Index}; +use ops::{Deref, DerefMut, CoerceUnsized}; use ptr; -use slice::SliceIndex; /// A mutable memory location. /// @@ -511,9 +510,8 @@ impl<T: ?Sized> Cell<T> { /// /// let slice: &mut [i32] = &mut [1, 2, 3]; /// let cell_slice: &Cell<[i32]> = Cell::from_mut(slice); - /// assert_eq!(cell_slice[..].len(), 3); + /// let slice_cell: &[Cell<i32>] = cell_slice.as_slice_of_cells(); /// - /// let slice_cell: &[Cell<i32>] = &cell_slice[..]; /// assert_eq!(slice_cell.len(), 3); /// ``` #[inline] @@ -548,15 +546,25 @@ impl<T: Default> Cell<T> { #[unstable(feature = "coerce_unsized", issue = "27732")] impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {} -#[unstable(feature = "as_cell", issue="43038")] -impl<T, I> Index<I> for Cell<[T]> - where I: SliceIndex<[Cell<T>]> -{ - type Output = I::Output; - - fn index(&self, index: I) -> &Self::Output { +impl<T> Cell<[T]> { + /// Returns a `&[Cell<T>]` from a `&Cell<[T]>` + /// + /// # Examples + /// + /// ``` + /// #![feature(as_cell)] + /// use std::cell::Cell; + /// + /// let slice: &mut [i32] = &mut [1, 2, 3]; + /// let cell_slice: &Cell<[i32]> = Cell::from_mut(slice); + /// let slice_cell: &[Cell<i32>] = cell_slice.as_slice_of_cells(); + /// + /// assert_eq!(slice_cell.len(), 3); + /// ``` + #[unstable(feature = "as_cell", issue="43038")] + pub fn as_slice_of_cells(&self) -> &[Cell<T>] { unsafe { - Index::index(&*(self as *const Cell<[T]> as *const [Cell<T>]), index) + &*(self as *const Cell<[T]> as *const [Cell<T>]) } } } |
