提交 4e1024f8 编写于 作者: B Brian Anderson

core: Put stability attributes all over the slice module

Much of this is as discussed[1]. Many things are marked

[1]: https://github.com/rust-lang/meeting-minutes/blob/master/Meeting-API-review-2014-08-06.md
上级 a4b354ca
...@@ -362,6 +362,7 @@ pub struct MutItems<'a, T> { ...@@ -362,6 +362,7 @@ pub struct MutItems<'a, T> {
impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> { impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> {
#[inline] #[inline]
#[allow(deprecated)] // mut_shift_ref
fn next(&mut self) -> Option<&'a mut T> { fn next(&mut self) -> Option<&'a mut T> {
if self.nelts == 0 { if self.nelts == 0 {
return None; return None;
...@@ -384,6 +385,7 @@ fn size_hint(&self) -> (uint, Option<uint>) { ...@@ -384,6 +385,7 @@ fn size_hint(&self) -> (uint, Option<uint>) {
impl<'a, T> DoubleEndedIterator<&'a mut T> for MutItems<'a, T> { impl<'a, T> DoubleEndedIterator<&'a mut T> for MutItems<'a, T> {
#[inline] #[inline]
#[allow(deprecated)] // mut_shift_ref
fn next_back(&mut self) -> Option<&'a mut T> { fn next_back(&mut self) -> Option<&'a mut T> {
if self.nelts == 0 { if self.nelts == 0 {
return None; return None;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
//! //!
//! For more details `std::slice`. //! For more details `std::slice`.
#![stable]
#![doc(primitive = "slice")] #![doc(primitive = "slice")]
// How this module is organized. // How this module is organized.
...@@ -57,6 +58,7 @@ ...@@ -57,6 +58,7 @@
// //
/// Extension methods for vectors /// Extension methods for vectors
#[unstable = "may merge with other traits; region parameter may disappear"]
pub trait ImmutableSlice<'a, T> { pub trait ImmutableSlice<'a, T> {
/** /**
* Returns a slice of self spanning the interval [`start`, `end`). * Returns a slice of self spanning the interval [`start`, `end`).
...@@ -64,6 +66,7 @@ pub trait ImmutableSlice<'a, T> { ...@@ -64,6 +66,7 @@ pub trait ImmutableSlice<'a, T> {
* Fails when the slice (or part of it) is outside the bounds of self, * Fails when the slice (or part of it) is outside the bounds of self,
* or when `start` > `end`. * or when `start` > `end`.
*/ */
#[unstable]
fn slice(&self, start: uint, end: uint) -> &'a [T]; fn slice(&self, start: uint, end: uint) -> &'a [T];
/** /**
...@@ -71,6 +74,7 @@ pub trait ImmutableSlice<'a, T> { ...@@ -71,6 +74,7 @@ pub trait ImmutableSlice<'a, T> {
* *
* Fails when `start` points outside the bounds of self. * Fails when `start` points outside the bounds of self.
*/ */
#[unstable]
fn slice_from(&self, start: uint) -> &'a [T]; fn slice_from(&self, start: uint) -> &'a [T];
/** /**
...@@ -78,6 +82,7 @@ pub trait ImmutableSlice<'a, T> { ...@@ -78,6 +82,7 @@ pub trait ImmutableSlice<'a, T> {
* *
* Fails when `end` points outside the bounds of self. * Fails when `end` points outside the bounds of self.
*/ */
#[unstable]
fn slice_to(&self, end: uint) -> &'a [T]; fn slice_to(&self, end: uint) -> &'a [T];
/// Divides one slice into two at an index. /// Divides one slice into two at an index.
...@@ -87,24 +92,29 @@ pub trait ImmutableSlice<'a, T> { ...@@ -87,24 +92,29 @@ pub trait ImmutableSlice<'a, T> {
/// indices from `[mid, len)` (excluding the index `len` itself). /// indices from `[mid, len)` (excluding the index `len` itself).
/// ///
/// Fails if `mid > len`. /// Fails if `mid > len`.
#[unstable]
fn split_at(&self, mid: uint) -> (&'a [T], &'a [T]); fn split_at(&self, mid: uint) -> (&'a [T], &'a [T]);
/// Returns an iterator over the vector /// Returns an iterator over the vector
#[unstable = "iterator type may change"]
fn iter(self) -> Items<'a, T>; fn iter(self) -> Items<'a, T>;
/// Returns an iterator over the subslices of the vector which are /// Returns an iterator over the subslices of the vector which are
/// separated by elements that match `pred`. The matched element /// separated by elements that match `pred`. The matched element
/// is not contained in the subslices. /// is not contained in the subslices.
#[unstable = "iterator type may change"]
fn split(self, pred: |&T|: 'a -> bool) -> Splits<'a, T>; fn split(self, pred: |&T|: 'a -> bool) -> Splits<'a, T>;
/// Returns an iterator over the subslices of the vector which are /// Returns an iterator over the subslices of the vector which are
/// separated by elements that match `pred`, limited to splitting /// separated by elements that match `pred`, limited to splitting
/// at most `n` times. The matched element is not contained in /// at most `n` times. The matched element is not contained in
/// the subslices. /// the subslices.
#[unstable = "iterator type may change"]
fn splitn(self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<'a, T>; fn splitn(self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<'a, T>;
/// Returns an iterator over the subslices of the vector which are /// Returns an iterator over the subslices of the vector which are
/// separated by elements that match `pred` limited to splitting /// separated by elements that match `pred` limited to splitting
/// at most `n` times. This starts at the end of the vector and /// at most `n` times. This starts at the end of the vector and
/// works backwards. The matched element is not contained in the /// works backwards. The matched element is not contained in the
/// subslices. /// subslices.
#[unstable = "iterator type may change"]
fn rsplitn(self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<'a, T>; fn rsplitn(self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<'a, T>;
/** /**
...@@ -129,6 +139,7 @@ pub trait ImmutableSlice<'a, T> { ...@@ -129,6 +139,7 @@ pub trait ImmutableSlice<'a, T> {
* ``` * ```
* *
*/ */
#[unstable = "iterator type may change"]
fn windows(self, size: uint) -> Windows<'a, T>; fn windows(self, size: uint) -> Windows<'a, T>;
/** /**
* *
...@@ -154,24 +165,30 @@ pub trait ImmutableSlice<'a, T> { ...@@ -154,24 +165,30 @@ pub trait ImmutableSlice<'a, T> {
* ``` * ```
* *
*/ */
#[unstable = "iterator type may change"]
fn chunks(self, size: uint) -> Chunks<'a, T>; fn chunks(self, size: uint) -> Chunks<'a, T>;
/// Returns the element of a vector at the given index, or `None` if the /// Returns the element of a vector at the given index, or `None` if the
/// index is out of bounds /// index is out of bounds
#[unstable]
fn get(&self, index: uint) -> Option<&'a T>; fn get(&self, index: uint) -> Option<&'a T>;
/// Returns the first element of a vector, or `None` if it is empty /// Returns the first element of a vector, or `None` if it is empty
#[unstable = "name may change"]
fn head(&self) -> Option<&'a T>; fn head(&self) -> Option<&'a T>;
/// Returns all but the first element of a vector /// Returns all but the first element of a vector
#[unstable = "name may change"]
fn tail(&self) -> &'a [T]; fn tail(&self) -> &'a [T];
/// Returns all but the first `n' elements of a vector /// Returns all but the first `n' elements of a vector
#[deprecated = "use slice_from"] #[deprecated = "use slice_from"]
fn tailn(&self, n: uint) -> &'a [T]; fn tailn(&self, n: uint) -> &'a [T];
/// Returns all but the last element of a vector /// Returns all but the last element of a vector
#[unstable = "name may change"]
fn init(&self) -> &'a [T]; fn init(&self) -> &'a [T];
/// Returns all but the last `n' elements of a vector /// Returns all but the last `n' elements of a vector
#[deprecated = "use slice_to but note the arguments are different"] #[deprecated = "use slice_to but note the arguments are different"]
fn initn(&self, n: uint) -> &'a [T]; fn initn(&self, n: uint) -> &'a [T];
/// Returns the last element of a vector, or `None` if it is empty. /// Returns the last element of a vector, or `None` if it is empty.
#[unstable = "name may change"]
fn last(&self) -> Option<&'a T>; fn last(&self) -> Option<&'a T>;
/// Returns a pointer to the element at the given index, without doing /// Returns a pointer to the element at the given index, without doing
...@@ -193,6 +210,7 @@ pub trait ImmutableSlice<'a, T> { ...@@ -193,6 +210,7 @@ pub trait ImmutableSlice<'a, T> {
* Modifying the vector may cause its buffer to be reallocated, which * Modifying the vector may cause its buffer to be reallocated, which
* would also make any pointers to it invalid. * would also make any pointers to it invalid.
*/ */
#[unstable]
fn as_ptr(&self) -> *const T; fn as_ptr(&self) -> *const T;
/** /**
...@@ -241,6 +259,7 @@ pub trait ImmutableSlice<'a, T> { ...@@ -241,6 +259,7 @@ pub trait ImmutableSlice<'a, T> {
* *
* Returns `None` if vector is empty * Returns `None` if vector is empty
*/ */
#[deprecated = "find some other way. sorry"]
fn shift_ref(&mut self) -> Option<&'a T>; fn shift_ref(&mut self) -> Option<&'a T>;
/** /**
...@@ -259,9 +278,11 @@ pub trait ImmutableSlice<'a, T> { ...@@ -259,9 +278,11 @@ pub trait ImmutableSlice<'a, T> {
* *
* Returns `None` if slice is empty. * Returns `None` if slice is empty.
*/ */
#[deprecated = "find some other way. sorry"]
fn pop_ref(&mut self) -> Option<&'a T>; fn pop_ref(&mut self) -> Option<&'a T>;
} }
#[unstable]
impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
#[inline] #[inline]
fn slice(&self, start: uint, end: uint) -> &'a [T] { fn slice(&self, start: uint, end: uint) -> &'a [T] {
...@@ -458,6 +479,7 @@ fn pop_ref(&mut self) -> Option<&'a T> { ...@@ -458,6 +479,7 @@ fn pop_ref(&mut self) -> Option<&'a T> {
/// Extension methods for vectors such that their elements are /// Extension methods for vectors such that their elements are
/// mutable. /// mutable.
#[experimental = "may merge with other traits; may lose region param; needs review"]
pub trait MutableSlice<'a, T> { pub trait MutableSlice<'a, T> {
/// Returns a mutable reference to the element at the given index, /// Returns a mutable reference to the element at the given index,
/// or `None` if the index is out of bounds /// or `None` if the index is out of bounds
...@@ -522,6 +544,7 @@ pub trait MutableSlice<'a, T> { ...@@ -522,6 +544,7 @@ pub trait MutableSlice<'a, T> {
* *
* Returns `None` if slice is empty * Returns `None` if slice is empty
*/ */
#[deprecated = "find some other way. sorry"]
fn mut_shift_ref(&mut self) -> Option<&'a mut T>; fn mut_shift_ref(&mut self) -> Option<&'a mut T>;
/** /**
...@@ -540,6 +563,7 @@ pub trait MutableSlice<'a, T> { ...@@ -540,6 +563,7 @@ pub trait MutableSlice<'a, T> {
* *
* Returns `None` if slice is empty. * Returns `None` if slice is empty.
*/ */
#[deprecated = "find some other way. sorry"]
fn mut_pop_ref(&mut self) -> Option<&'a mut T>; fn mut_pop_ref(&mut self) -> Option<&'a mut T>;
/// Swaps two elements in a vector. /// Swaps two elements in a vector.
...@@ -664,6 +688,7 @@ pub trait MutableSlice<'a, T> { ...@@ -664,6 +688,7 @@ pub trait MutableSlice<'a, T> {
unsafe fn copy_memory(self, src: &[T]); unsafe fn copy_memory(self, src: &[T]);
} }
#[experimental = "trait is experimental"]
impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { impl<'a,T> MutableSlice<'a, T> for &'a mut [T] {
#[inline] #[inline]
fn get_mut(self, index: uint) -> Option<&'a mut T> { fn get_mut(self, index: uint) -> Option<&'a mut T> {
...@@ -812,6 +837,7 @@ unsafe fn copy_memory(self, src: &[T]) { ...@@ -812,6 +837,7 @@ unsafe fn copy_memory(self, src: &[T]) {
} }
/// Extension methods for vectors contain `PartialEq` elements. /// Extension methods for vectors contain `PartialEq` elements.
#[unstable = "may merge with other traits"]
pub trait ImmutablePartialEqSlice<T:PartialEq> { pub trait ImmutablePartialEqSlice<T:PartialEq> {
/// Find the first index containing a matching value /// Find the first index containing a matching value
fn position_elem(&self, t: &T) -> Option<uint>; fn position_elem(&self, t: &T) -> Option<uint>;
...@@ -829,6 +855,7 @@ pub trait ImmutablePartialEqSlice<T:PartialEq> { ...@@ -829,6 +855,7 @@ pub trait ImmutablePartialEqSlice<T:PartialEq> {
fn ends_with(&self, needle: &[T]) -> bool; fn ends_with(&self, needle: &[T]) -> bool;
} }
#[unstable = "trait is unstable"]
impl<'a,T:PartialEq> ImmutablePartialEqSlice<T> for &'a [T] { impl<'a,T:PartialEq> ImmutablePartialEqSlice<T> for &'a [T] {
#[inline] #[inline]
fn position_elem(&self, x: &T) -> Option<uint> { fn position_elem(&self, x: &T) -> Option<uint> {
...@@ -859,6 +886,7 @@ fn ends_with(&self, needle: &[T]) -> bool { ...@@ -859,6 +886,7 @@ fn ends_with(&self, needle: &[T]) -> bool {
} }
/// Extension methods for vectors containing `Ord` elements. /// Extension methods for vectors containing `Ord` elements.
#[unstable = "may merge with other traits"]
pub trait ImmutableOrdSlice<T: Ord> { pub trait ImmutableOrdSlice<T: Ord> {
/** /**
* Binary search a sorted vector for a given element. * Binary search a sorted vector for a given element.
...@@ -880,8 +908,10 @@ pub trait ImmutableOrdSlice<T: Ord> { ...@@ -880,8 +908,10 @@ pub trait ImmutableOrdSlice<T: Ord> {
fn binary_search_elem(&self, x: &T) -> BinarySearchResult; fn binary_search_elem(&self, x: &T) -> BinarySearchResult;
} }
#[unstable = "trait is unstable"]
impl<'a, T: Ord> ImmutableOrdSlice<T> for &'a [T] { impl<'a, T: Ord> ImmutableOrdSlice<T> for &'a [T] {
#[deprecated = "use binary_search_elem"] #[deprecated = "use binary_search_elem"]
#[allow(deprecated)]
fn bsearch_elem(&self, x: &T) -> Option<uint> { fn bsearch_elem(&self, x: &T) -> Option<uint> {
self.bsearch(|p| p.cmp(x)) self.bsearch(|p| p.cmp(x))
} }
...@@ -893,6 +923,7 @@ fn binary_search_elem(&self, x: &T) -> BinarySearchResult { ...@@ -893,6 +923,7 @@ fn binary_search_elem(&self, x: &T) -> BinarySearchResult {
} }
/// Trait for &[T] where T is Cloneable /// Trait for &[T] where T is Cloneable
#[unstable = "may merge with other traits"]
pub trait MutableCloneableSlice<T> { pub trait MutableCloneableSlice<T> {
/// Copies as many elements from `src` as it can into `self` (the /// Copies as many elements from `src` as it can into `self` (the
/// shorter of `self.len()` and `src.len()`). Returns the number /// shorter of `self.len()` and `src.len()`). Returns the number
...@@ -922,6 +953,7 @@ fn copy_from(self, s: &[T]) -> uint { self.clone_from_slice(s) } ...@@ -922,6 +953,7 @@ fn copy_from(self, s: &[T]) -> uint { self.clone_from_slice(s) }
fn clone_from_slice(self, &[T]) -> uint; fn clone_from_slice(self, &[T]) -> uint;
} }
#[unstable = "trait is unstable"]
impl<'a, T:Clone> MutableCloneableSlice<T> for &'a mut [T] { impl<'a, T:Clone> MutableCloneableSlice<T> for &'a mut [T] {
#[inline] #[inline]
fn clone_from_slice(self, src: &[T]) -> uint { fn clone_from_slice(self, src: &[T]) -> uint {
...@@ -940,16 +972,19 @@ fn clone_from_slice(self, src: &[T]) -> uint { ...@@ -940,16 +972,19 @@ fn clone_from_slice(self, src: &[T]) -> uint {
// //
/// Any vector that can be represented as a slice. /// Any vector that can be represented as a slice.
#[unstable = "may merge with other traits"]
pub trait Slice<T> { pub trait Slice<T> {
/// Work with `self` as a slice. /// Work with `self` as a slice.
fn as_slice<'a>(&'a self) -> &'a [T]; fn as_slice<'a>(&'a self) -> &'a [T];
} }
#[unstable = "trait is unstable"]
impl<'a,T> Slice<T> for &'a [T] { impl<'a,T> Slice<T> for &'a [T] {
#[inline(always)] #[inline(always)]
fn as_slice<'a>(&'a self) -> &'a [T] { *self } fn as_slice<'a>(&'a self) -> &'a [T] { *self }
} }
#[experimental = "trait is experimental"]
impl<'a, T> Collection for &'a [T] { impl<'a, T> Collection for &'a [T] {
/// Returns the length of a vector /// Returns the length of a vector
#[inline] #[inline]
...@@ -958,6 +993,7 @@ fn len(&self) -> uint { ...@@ -958,6 +993,7 @@ fn len(&self) -> uint {
} }
} }
#[unstable = "waiting for DST"]
impl<'a, T> Default for &'a [T] { impl<'a, T> Default for &'a [T] {
fn default() -> &'a [T] { &[] } fn default() -> &'a [T] { &[] }
} }
...@@ -972,6 +1008,7 @@ fn default() -> &'a [T] { &[] } ...@@ -972,6 +1008,7 @@ fn default() -> &'a [T] { &[] }
// The shared definition of the `Item` and `MutItems` iterators // The shared definition of the `Item` and `MutItems` iterators
macro_rules! iterator { macro_rules! iterator {
(struct $name:ident -> $ptr:ty, $elem:ty) => { (struct $name:ident -> $ptr:ty, $elem:ty) => {
#[experimental = "needs review"]
impl<'a, T> Iterator<$elem> for $name<'a, T> { impl<'a, T> Iterator<$elem> for $name<'a, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<$elem> { fn next(&mut self) -> Option<$elem> {
...@@ -1007,6 +1044,7 @@ fn size_hint(&self) -> (uint, Option<uint>) { ...@@ -1007,6 +1044,7 @@ fn size_hint(&self) -> (uint, Option<uint>) {
} }
} }
#[experimental = "needs review"]
impl<'a, T> DoubleEndedIterator<$elem> for $name<'a, T> { impl<'a, T> DoubleEndedIterator<$elem> for $name<'a, T> {
#[inline] #[inline]
fn next_back(&mut self) -> Option<$elem> { fn next_back(&mut self) -> Option<$elem> {
...@@ -1034,6 +1072,7 @@ fn next_back(&mut self) -> Option<$elem> { ...@@ -1034,6 +1072,7 @@ fn next_back(&mut self) -> Option<$elem> {
} }
/// Immutable slice iterator /// Immutable slice iterator
#[experimental = "needs review"]
pub struct Items<'a, T> { pub struct Items<'a, T> {
ptr: *const T, ptr: *const T,
end: *const T, end: *const T,
...@@ -1042,12 +1081,15 @@ pub struct Items<'a, T> { ...@@ -1042,12 +1081,15 @@ pub struct Items<'a, T> {
iterator!{struct Items -> *const T, &'a T} iterator!{struct Items -> *const T, &'a T}
#[experimental = "needs review"]
impl<'a, T> ExactSize<&'a T> for Items<'a, T> {} impl<'a, T> ExactSize<&'a T> for Items<'a, T> {}
#[experimental = "needs review"]
impl<'a, T> Clone for Items<'a, T> { impl<'a, T> Clone for Items<'a, T> {
fn clone(&self) -> Items<'a, T> { *self } fn clone(&self) -> Items<'a, T> { *self }
} }
#[experimental = "needs review"]
impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> { impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
#[inline] #[inline]
fn indexable(&self) -> uint { fn indexable(&self) -> uint {
...@@ -1073,6 +1115,7 @@ fn idx(&mut self, index: uint) -> Option<&'a T> { ...@@ -1073,6 +1115,7 @@ fn idx(&mut self, index: uint) -> Option<&'a T> {
} }
/// Mutable slice iterator /// Mutable slice iterator
#[experimental = "needs review"]
pub struct MutItems<'a, T> { pub struct MutItems<'a, T> {
ptr: *mut T, ptr: *mut T,
end: *mut T, end: *mut T,
...@@ -1082,16 +1125,19 @@ pub struct MutItems<'a, T> { ...@@ -1082,16 +1125,19 @@ pub struct MutItems<'a, T> {
iterator!{struct MutItems -> *mut T, &'a mut T} iterator!{struct MutItems -> *mut T, &'a mut T}
#[experimental = "needs review"]
impl<'a, T> ExactSize<&'a mut T> for MutItems<'a, T> {} impl<'a, T> ExactSize<&'a mut T> for MutItems<'a, T> {}
/// An iterator over the slices of a vector separated by elements that /// An iterator over the slices of a vector separated by elements that
/// match a predicate function. /// match a predicate function.
#[experimental = "needs review"]
pub struct Splits<'a, T> { pub struct Splits<'a, T> {
v: &'a [T], v: &'a [T],
pred: |t: &T|: 'a -> bool, pred: |t: &T|: 'a -> bool,
finished: bool finished: bool
} }
#[experimental = "needs review"]
impl<'a, T> Iterator<&'a [T]> for Splits<'a, T> { impl<'a, T> Iterator<&'a [T]> for Splits<'a, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<&'a [T]> { fn next(&mut self) -> Option<&'a [T]> {
...@@ -1120,6 +1166,7 @@ fn size_hint(&self) -> (uint, Option<uint>) { ...@@ -1120,6 +1166,7 @@ fn size_hint(&self) -> (uint, Option<uint>) {
} }
} }
#[experimental = "needs review"]
impl<'a, T> DoubleEndedIterator<&'a [T]> for Splits<'a, T> { impl<'a, T> DoubleEndedIterator<&'a [T]> for Splits<'a, T> {
#[inline] #[inline]
fn next_back(&mut self) -> Option<&'a [T]> { fn next_back(&mut self) -> Option<&'a [T]> {
...@@ -1141,12 +1188,14 @@ fn next_back(&mut self) -> Option<&'a [T]> { ...@@ -1141,12 +1188,14 @@ fn next_back(&mut self) -> Option<&'a [T]> {
/// An iterator over the subslices of the vector which are separated /// An iterator over the subslices of the vector which are separated
/// by elements that match `pred`. /// by elements that match `pred`.
#[experimental = "needs review"]
pub struct MutSplits<'a, T> { pub struct MutSplits<'a, T> {
v: &'a mut [T], v: &'a mut [T],
pred: |t: &T|: 'a -> bool, pred: |t: &T|: 'a -> bool,
finished: bool finished: bool
} }
#[experimental = "needs review"]
impl<'a, T> Iterator<&'a mut [T]> for MutSplits<'a, T> { impl<'a, T> Iterator<&'a mut [T]> for MutSplits<'a, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<&'a mut [T]> { fn next(&mut self) -> Option<&'a mut [T]> {
...@@ -1183,6 +1232,7 @@ fn size_hint(&self) -> (uint, Option<uint>) { ...@@ -1183,6 +1232,7 @@ fn size_hint(&self) -> (uint, Option<uint>) {
} }
} }
#[experimental = "needs review"]
impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutSplits<'a, T> { impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutSplits<'a, T> {
#[inline] #[inline]
fn next_back(&mut self) -> Option<&'a mut [T]> { fn next_back(&mut self) -> Option<&'a mut [T]> {
...@@ -1207,12 +1257,14 @@ fn next_back(&mut self) -> Option<&'a mut [T]> { ...@@ -1207,12 +1257,14 @@ fn next_back(&mut self) -> Option<&'a mut [T]> {
/// An iterator over the slices of a vector separated by elements that /// An iterator over the slices of a vector separated by elements that
/// match a predicate function, splitting at most a fixed number of times. /// match a predicate function, splitting at most a fixed number of times.
#[experimental = "needs review"]
pub struct SplitsN<'a, T> { pub struct SplitsN<'a, T> {
iter: Splits<'a, T>, iter: Splits<'a, T>,
count: uint, count: uint,
invert: bool invert: bool
} }
#[experimental = "needs review"]
impl<'a, T> Iterator<&'a [T]> for SplitsN<'a, T> { impl<'a, T> Iterator<&'a [T]> for SplitsN<'a, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<&'a [T]> { fn next(&mut self) -> Option<&'a [T]> {
...@@ -1242,11 +1294,13 @@ fn size_hint(&self) -> (uint, Option<uint>) { ...@@ -1242,11 +1294,13 @@ fn size_hint(&self) -> (uint, Option<uint>) {
/// An iterator over the (overlapping) slices of length `size` within /// An iterator over the (overlapping) slices of length `size` within
/// a vector. /// a vector.
#[deriving(Clone)] #[deriving(Clone)]
#[experimental = "needs review"]
pub struct Windows<'a, T> { pub struct Windows<'a, T> {
v: &'a [T], v: &'a [T],
size: uint size: uint
} }
#[experimental = "needs review"]
impl<'a, T> Iterator<&'a [T]> for Windows<'a, T> { impl<'a, T> Iterator<&'a [T]> for Windows<'a, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<&'a [T]> { fn next(&mut self) -> Option<&'a [T]> {
...@@ -1276,11 +1330,13 @@ fn size_hint(&self) -> (uint, Option<uint>) { ...@@ -1276,11 +1330,13 @@ fn size_hint(&self) -> (uint, Option<uint>) {
/// When the vector len is not evenly divided by the chunk size, /// When the vector len is not evenly divided by the chunk size,
/// the last slice of the iteration will be the remainder. /// the last slice of the iteration will be the remainder.
#[deriving(Clone)] #[deriving(Clone)]
#[experimental = "needs review"]
pub struct Chunks<'a, T> { pub struct Chunks<'a, T> {
v: &'a [T], v: &'a [T],
size: uint size: uint
} }
#[experimental = "needs review"]
impl<'a, T> Iterator<&'a [T]> for Chunks<'a, T> { impl<'a, T> Iterator<&'a [T]> for Chunks<'a, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<&'a [T]> { fn next(&mut self) -> Option<&'a [T]> {
...@@ -1306,6 +1362,7 @@ fn size_hint(&self) -> (uint, Option<uint>) { ...@@ -1306,6 +1362,7 @@ fn size_hint(&self) -> (uint, Option<uint>) {
} }
} }
#[experimental = "needs review"]
impl<'a, T> DoubleEndedIterator<&'a [T]> for Chunks<'a, T> { impl<'a, T> DoubleEndedIterator<&'a [T]> for Chunks<'a, T> {
#[inline] #[inline]
fn next_back(&mut self) -> Option<&'a [T]> { fn next_back(&mut self) -> Option<&'a [T]> {
...@@ -1321,6 +1378,7 @@ fn next_back(&mut self) -> Option<&'a [T]> { ...@@ -1321,6 +1378,7 @@ fn next_back(&mut self) -> Option<&'a [T]> {
} }
} }
#[experimental = "needs review"]
impl<'a, T> RandomAccessIterator<&'a [T]> for Chunks<'a, T> { impl<'a, T> RandomAccessIterator<&'a [T]> for Chunks<'a, T> {
#[inline] #[inline]
fn indexable(&self) -> uint { fn indexable(&self) -> uint {
...@@ -1344,11 +1402,13 @@ fn idx(&mut self, index: uint) -> Option<&'a [T]> { ...@@ -1344,11 +1402,13 @@ fn idx(&mut self, index: uint) -> Option<&'a [T]> {
/// An iterator over a vector in (non-overlapping) mutable chunks (`size` elements at a time). When /// An iterator over a vector in (non-overlapping) mutable chunks (`size` elements at a time). When
/// the vector len is not evenly divided by the chunk size, the last slice of the iteration will be /// the vector len is not evenly divided by the chunk size, the last slice of the iteration will be
/// the remainder. /// the remainder.
#[experimental = "needs review"]
pub struct MutChunks<'a, T> { pub struct MutChunks<'a, T> {
v: &'a mut [T], v: &'a mut [T],
chunk_size: uint chunk_size: uint
} }
#[experimental = "needs review"]
impl<'a, T> Iterator<&'a mut [T]> for MutChunks<'a, T> { impl<'a, T> Iterator<&'a mut [T]> for MutChunks<'a, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<&'a mut [T]> { fn next(&mut self) -> Option<&'a mut [T]> {
...@@ -1375,6 +1435,7 @@ fn size_hint(&self) -> (uint, Option<uint>) { ...@@ -1375,6 +1435,7 @@ fn size_hint(&self) -> (uint, Option<uint>) {
} }
} }
#[experimental = "needs review"]
impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> { impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> {
#[inline] #[inline]
fn next_back(&mut self) -> Option<&'a mut [T]> { fn next_back(&mut self) -> Option<&'a mut [T]> {
...@@ -1401,6 +1462,7 @@ fn next_back(&mut self) -> Option<&'a mut [T]> { ...@@ -1401,6 +1462,7 @@ fn next_back(&mut self) -> Option<&'a mut [T]> {
/// succeeded, and the contained value is an index where a matching /// succeeded, and the contained value is an index where a matching
/// value could be inserted while maintaining sort order. /// value could be inserted while maintaining sort order.
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
#[experimental = "needs review"]
pub enum BinarySearchResult { pub enum BinarySearchResult {
/// The index of the found value. /// The index of the found value.
Found(uint), Found(uint),
...@@ -1408,6 +1470,7 @@ pub enum BinarySearchResult { ...@@ -1408,6 +1470,7 @@ pub enum BinarySearchResult {
NotFound(uint) NotFound(uint)
} }
#[experimental = "needs review"]
impl BinarySearchResult { impl BinarySearchResult {
/// Converts a `Found` to `Some`, `NotFound` to `None`. /// Converts a `Found` to `Some`, `NotFound` to `None`.
/// Similar to `Result::ok`. /// Similar to `Result::ok`.
...@@ -1437,6 +1500,7 @@ pub fn not_found(&self) -> Option<uint> { ...@@ -1437,6 +1500,7 @@ pub fn not_found(&self) -> Option<uint> {
/** /**
* Converts a pointer to A into a slice of length 1 (without copying). * Converts a pointer to A into a slice of length 1 (without copying).
*/ */
#[unstable = "waiting for DST"]
pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] { pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
unsafe { unsafe {
transmute(RawSlice { data: s, len: 1 }) transmute(RawSlice { data: s, len: 1 })
...@@ -1446,6 +1510,7 @@ pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] { ...@@ -1446,6 +1510,7 @@ pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
/** /**
* Converts a pointer to A into a slice of length 1 (without copying). * Converts a pointer to A into a slice of length 1 (without copying).
*/ */
#[unstable = "waiting for DST"]
pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] { pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
unsafe { unsafe {
let ptr: *const A = transmute(s); let ptr: *const A = transmute(s);
...@@ -1461,6 +1526,7 @@ pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] { ...@@ -1461,6 +1526,7 @@ pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
// //
/// Unsafe operations /// Unsafe operations
#[experimental = "needs review"]
pub mod raw { pub mod raw {
use mem::transmute; use mem::transmute;
use ptr::RawPtr; use ptr::RawPtr;
...@@ -1526,6 +1592,7 @@ pub unsafe fn pop_ptr<T>(slice: &mut Slice<T>) -> Option<*const T> { ...@@ -1526,6 +1592,7 @@ pub unsafe fn pop_ptr<T>(slice: &mut Slice<T>) -> Option<*const T> {
} }
/// Operations on `[u8]`. /// Operations on `[u8]`.
#[experimental = "needs review"]
pub mod bytes { pub mod bytes {
use collections::Collection; use collections::Collection;
use ptr; use ptr;
...@@ -1563,6 +1630,7 @@ pub fn copy_memory(dst: &mut [u8], src: &[u8]) { ...@@ -1563,6 +1630,7 @@ pub fn copy_memory(dst: &mut [u8], src: &[u8]) {
// Boilerplate traits // Boilerplate traits
// //
#[unstable = "waiting for DST"]
impl<'a,T:PartialEq> PartialEq for &'a [T] { impl<'a,T:PartialEq> PartialEq for &'a [T] {
fn eq(&self, other: & &'a [T]) -> bool { fn eq(&self, other: & &'a [T]) -> bool {
self.len() == other.len() && self.len() == other.len() &&
...@@ -1574,19 +1642,23 @@ fn ne(&self, other: & &'a [T]) -> bool { ...@@ -1574,19 +1642,23 @@ fn ne(&self, other: & &'a [T]) -> bool {
} }
} }
#[unstable = "waiting for DST"]
impl<'a,T:Eq> Eq for &'a [T] {} impl<'a,T:Eq> Eq for &'a [T] {}
#[unstable = "waiting for DST"]
impl<'a,T:PartialEq, V: Slice<T>> Equiv<V> for &'a [T] { impl<'a,T:PartialEq, V: Slice<T>> Equiv<V> for &'a [T] {
#[inline] #[inline]
fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() }
} }
#[unstable = "waiting for DST"]
impl<'a,T:Ord> Ord for &'a [T] { impl<'a,T:Ord> Ord for &'a [T] {
fn cmp(&self, other: & &'a [T]) -> Ordering { fn cmp(&self, other: & &'a [T]) -> Ordering {
order::cmp(self.iter(), other.iter()) order::cmp(self.iter(), other.iter())
} }
} }
#[unstable = "waiting for DST"]
impl<'a, T: PartialOrd> PartialOrd for &'a [T] { impl<'a, T: PartialOrd> PartialOrd for &'a [T] {
#[inline] #[inline]
fn partial_cmp(&self, other: &&'a [T]) -> Option<Ordering> { fn partial_cmp(&self, other: &&'a [T]) -> Option<Ordering> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册