diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 080d34dbda5..1d679f18feb 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -246,7 +246,7 @@ impl BorrowFrom> for T { } } -#[experimental = "Deref is experimental."] +#[stable] impl Deref for Arc { type Target = T; @@ -290,7 +290,7 @@ impl Arc { } #[unsafe_destructor] -#[experimental = "waiting on stability of Drop"] +#[stable] impl Drop for Arc { /// Drops the `Arc`. /// @@ -418,7 +418,7 @@ impl Clone for Weak { } #[unsafe_destructor] -#[experimental = "Weak pointers may not belong in this module."] +#[stable] impl Drop for Weak { /// Drops the `Weak`. /// diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 2c318181b09..33d1cc7f4c7 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -155,12 +155,14 @@ impl fmt::Show for Box { } } +#[stable] impl Deref for Box { type Target = T; fn deref(&self) -> &T { &**self } } +#[stable] impl DerefMut for Box { fn deref_mut(&mut self) -> &mut T { &mut **self } } diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index d9239e93a07..1621e1934fa 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -354,7 +354,7 @@ impl BorrowFrom> for T { } } -#[experimental = "Deref is experimental."] +#[stable] impl Deref for Rc { type Target = T; @@ -365,7 +365,7 @@ impl Deref for Rc { } #[unsafe_destructor] -#[experimental = "Drop is experimental."] +#[stable] impl Drop for Rc { /// Drops the `Rc`. /// @@ -656,7 +656,7 @@ impl Weak { } #[unsafe_destructor] -#[experimental = "Weak pointers may not belong in this module."] +#[stable] impl Drop for Weak { /// Drops the `Weak`. /// diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 82002f16133..d95c666b586 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -148,6 +148,7 @@ //! ``` #![allow(missing_docs)] +#![stable] use core::prelude::*; @@ -561,11 +562,13 @@ impl BinaryHeap { } /// `BinaryHeap` iterator. +#[stable] pub struct Iter <'a, T: 'a> { iter: slice::Iter<'a, T>, } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` +#[stable] impl<'a, T> Clone for Iter<'a, T> { fn clone(&self) -> Iter<'a, T> { Iter { iter: self.iter.clone() } @@ -593,6 +596,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { impl<'a, T> ExactSizeIterator for Iter<'a, T> {} /// An iterator that moves out of a `BinaryHeap`. +#[stable] pub struct IntoIter { iter: vec::IntoIter, } @@ -618,6 +622,7 @@ impl DoubleEndedIterator for IntoIter { impl ExactSizeIterator for IntoIter {} /// An iterator that drains a `BinaryHeap`. +#[unstable = "recent addition"] pub struct Drain<'a, T: 'a> { iter: vec::Drain<'a, T>, } diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 5aec9973c81..b3c1486eaf3 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -19,6 +19,8 @@ // Backlinks over DList::prev are raw pointers that form a full chain in // the reverse direction. +#![stable] + use core::prelude::*; use alloc::boxed::Box; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index db236795038..c9b090bfb23 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -65,19 +65,23 @@ pub mod string; pub mod vec; pub mod vec_map; +#[stable] pub mod bitv { pub use bit::{Bitv, Iter}; } +#[stable] pub mod bitv_set { pub use bit::{BitvSet, Union, Intersection, Difference, SymmetricDifference}; pub use bit::SetIter as Iter; } +#[stable] pub mod btree_map { pub use btree::map::*; } +#[stable] pub mod btree_set { pub use btree::set::*; } @@ -109,8 +113,7 @@ mod prelude { pub use core::iter::range; pub use core::iter::{FromIterator, Extend, IteratorExt}; pub use core::iter::{Iterator, DoubleEndedIterator, RandomAccessIterator}; - pub use core::iter::{IteratorCloneExt, CloneIteratorExt}; - pub use core::iter::{IteratorOrdExt, MutableDoubleEndedIterator, ExactSizeIterator}; + pub use core::iter::{ExactSizeIterator}; pub use core::kinds::{Copy, Send, Sized, Sync}; pub use core::mem::drop; pub use core::ops::{Drop, Fn, FnMut, FnOnce}; diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index 8a83bf25e9b..0ffede776ea 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -12,6 +12,8 @@ //! ends of the container. It also has `O(1)` indexing like a vector. The contained elements are //! not required to be copyable, and the queue will be sendable if the contained type is sendable. +#![stable] + use core::prelude::*; use core::cmp::Ordering; diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 8050c44f542..1afdd8c023b 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -86,6 +86,7 @@ //! * Further iterators exist that split, chunk or permute the slice. #![doc(primitive = "slice")] +#![stable] use alloc::boxed::Box; use core::borrow::{BorrowFrom, BorrowFromMut, ToOwned}; @@ -121,8 +122,10 @@ pub type MutItems<'a, T:'a> = IterMut<'a, T>; //////////////////////////////////////////////////////////////////////////////// /// Allocating extension methods for slices. -#[unstable = "needs associated types, may merge with other traits"] -pub trait SliceExt for Sized? { +pub trait SliceExt for Sized? { + #[stable] + type Item; + /// Sorts the slice, in place, using `compare` to compare /// elements. /// @@ -561,8 +564,10 @@ pub trait SliceExt for Sized? { fn as_mut_ptr(&mut self) -> *mut T; } -#[unstable = "trait is unstable"] -impl SliceExt for [T] { +#[stable] +impl SliceExt for [T] { + type Item = T; + #[inline] fn sort_by(&mut self, compare: F) where F: FnMut(&T, &T) -> Ordering { merge_sort(self, compare) @@ -1113,7 +1118,10 @@ struct SizeDirection { dir: Direction, } -impl Iterator<(uint, uint)> for ElementSwaps { +#[stable] +impl Iterator for ElementSwaps { + type Item = (uint, uint); + #[inline] fn next(&mut self) -> Option<(uint, uint)> { fn new_pos(i: uint, s: Direction) -> uint { diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index ecf17820d2d..9f3ab6dd5c0 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -165,6 +165,7 @@ enum DecompositionType { /// External iterator for a string's decomposition's characters. /// Use with the `std::iter` module. #[derive(Clone)] +#[unstable] pub struct Decompositions<'a> { kind: DecompositionType, iter: Chars<'a>, @@ -172,6 +173,7 @@ pub struct Decompositions<'a> { sorted: bool } +#[stable] impl<'a> Iterator for Decompositions<'a> { type Item = char; @@ -253,6 +255,7 @@ enum RecompositionState { /// External iterator for a string's recomposition's characters. /// Use with the `std::iter` module. #[derive(Clone)] +#[unstable] pub struct Recompositions<'a> { iter: Decompositions<'a>, state: RecompositionState, @@ -261,6 +264,7 @@ pub struct Recompositions<'a> { last_ccc: Option } +#[stable] impl<'a> Iterator for Recompositions<'a> { type Item = char; @@ -348,10 +352,12 @@ impl<'a> Iterator for Recompositions<'a> { /// External iterator for a string's UTF16 codeunits. /// Use with the `std::iter` module. #[derive(Clone)] +#[unstable] pub struct Utf16Units<'a> { encoder: Utf16Encoder> } +#[stable] impl<'a> Iterator for Utf16Units<'a> { type Item = u16; diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 11e6c48cfdb..6d7ebeff094 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -687,7 +687,7 @@ impl fmt::Show for FromUtf16Error { } } -#[experimental = "waiting on FromIterator stabilization"] +#[stable] impl FromIterator for String { fn from_iter>(iterator: I) -> String { let mut buf = String::new(); @@ -696,7 +696,7 @@ impl FromIterator for String { } } -#[experimental = "waiting on FromIterator stabilization"] +#[stable] impl<'a> FromIterator<&'a str> for String { fn from_iter>(iterator: I) -> String { let mut buf = String::new(); @@ -808,7 +808,7 @@ impl hash::Hash for String { } } -#[experimental = "waiting on Add stabilization"] +#[unstable = "recent addition, needs more experience"] impl<'a> Add<&'a str> for String { type Output = String; @@ -840,7 +840,7 @@ impl ops::Slice for String { } } -#[experimental = "waiting on Deref stabilization"] +#[stable] impl ops::Deref for String { type Target = str; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index e0ed8e27e99..86f5f61b210 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1251,19 +1251,19 @@ impl ops::SliceMut for Vec { } } -#[experimental = "waiting on Deref stability"] +#[stable] impl ops::Deref for Vec { type Target = [T]; fn deref<'a>(&'a self) -> &'a [T] { self.as_slice() } } -#[experimental = "waiting on DerefMut stability"] +#[stable] impl ops::DerefMut for Vec { fn deref_mut<'a>(&'a mut self) -> &'a mut [T] { self.as_mut_slice() } } -#[experimental = "waiting on FromIterator stability"] +#[stable] impl FromIterator for Vec { #[inline] fn from_iter>(mut iterator: I) -> Vec { @@ -1393,6 +1393,7 @@ impl AsSlice for Vec { } } +#[unstable = "recent addition, needs more experience"] impl<'a, T: Clone> Add<&'a [T]> for Vec { type Output = Vec; @@ -1404,6 +1405,7 @@ impl<'a, T: Clone> Add<&'a [T]> for Vec { } #[unsafe_destructor] +#[stable] impl Drop for Vec { fn drop(&mut self) { // This is (and should always remain) a no-op if the fields are @@ -1449,6 +1451,7 @@ impl<'a> fmt::Writer for Vec { /// A clone-on-write vector pub type CowVec<'a, T> = Cow<'a, Vec, [T]>; +#[unstable] impl<'a, T> FromIterator for CowVec<'a, T> where T: Clone { fn from_iter>(it: I) -> CowVec<'a, T> { Cow::Owned(FromIterator::from_iter(it)) @@ -1494,6 +1497,7 @@ impl IntoIter { } } +#[stable] impl Iterator for IntoIter { type Item = T; @@ -1530,6 +1534,7 @@ impl Iterator for IntoIter { } } +#[stable] impl DoubleEndedIterator for IntoIter { #[inline] fn next_back<'a>(&'a mut self) -> Option { @@ -1553,9 +1558,11 @@ impl DoubleEndedIterator for IntoIter { } } +#[stable] impl ExactSizeIterator for IntoIter {} #[unsafe_destructor] +#[stable] impl Drop for IntoIter { fn drop(&mut self) { // destroy the remaining elements @@ -1577,6 +1584,7 @@ pub struct Drain<'a, T> { marker: ContravariantLifetime<'a>, } +#[stable] impl<'a, T> Iterator for Drain<'a, T> { type Item = T; @@ -1613,6 +1621,7 @@ impl<'a, T> Iterator for Drain<'a, T> { } } +#[stable] impl<'a, T> DoubleEndedIterator for Drain<'a, T> { #[inline] fn next_back(&mut self) -> Option { @@ -1636,9 +1645,11 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T> { } } +#[stable] impl<'a, T> ExactSizeIterator for Drain<'a, T> {} #[unsafe_destructor] +#[stable] impl<'a, T> Drop for Drain<'a, T> { fn drop(&mut self) { // self.ptr == self.end == null if drop has already been called, @@ -1671,7 +1682,7 @@ impl<'a, T> Deref for DerefVec<'a, T> { // Prevent the inner `Vec` from attempting to deallocate memory. #[unsafe_destructor] -#[experimental] +#[stable] impl<'a, T> Drop for DerefVec<'a, T> { fn drop(&mut self) { self.x.len = 0; diff --git a/src/libcore/borrow.rs b/src/libcore/borrow.rs index 7e4d73d598d..63b3be00f55 100644 --- a/src/libcore/borrow.rs +++ b/src/libcore/borrow.rs @@ -191,6 +191,7 @@ impl<'a, T, Sized? B> Cow<'a, T, B> where B: ToOwned { } } +#[stable] impl<'a, T, Sized? B> Deref for Cow<'a, T, B> where B: ToOwned { type Target = B; diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index eb772388dce..fd18d6ac3f3 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -419,7 +419,7 @@ pub struct Ref<'b, T:'b> { _borrow: BorrowRef<'b>, } -#[unstable = "waiting for `Deref` to become stable"] +#[stable] impl<'b, T> Deref for Ref<'b, T> { type Target = T; @@ -477,7 +477,7 @@ pub struct RefMut<'b, T:'b> { _borrow: BorrowRefMut<'b>, } -#[unstable = "waiting for `Deref` to become stable"] +#[stable] impl<'b, T> Deref for RefMut<'b, T> { type Target = T; @@ -487,7 +487,7 @@ impl<'b, T> Deref for RefMut<'b, T> { } } -#[unstable = "waiting for `DerefMut` to become stable"] +#[stable] impl<'b, T> DerefMut for RefMut<'b, T> { #[inline] fn deref_mut<'a>(&'a mut self) -> &'a mut T { diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 291b7f2ece4..caac894c0da 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -314,6 +314,7 @@ pub struct EscapeUnicode { } #[derive(Clone)] +#[unstable] enum EscapeUnicodeState { Backslash, Type, @@ -375,6 +376,7 @@ pub struct EscapeDefault { } #[derive(Clone)] +#[unstable] enum EscapeDefaultState { Backslash(char), Char(char), diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index e7e32cec177..b262054992c 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -54,6 +54,8 @@ //! //! This `for` loop syntax can be applied to any iterator over any type. +#![stable] + use self::MinMaxResult::*; use clone::Clone; @@ -79,11 +81,13 @@ use uint; /// it wishes, either by returning `None` infinitely, or by doing something /// else. #[lang="iterator"] -#[unstable = "just split up for object safety"] +#[stable] pub trait Iterator { + #[stable] type Item; /// Advance the iterator and return the next value. Return `None` when the end is reached. + #[stable] fn next(&mut self) -> Option; /// Returns a lower and upper bound on the remaining length of the iterator. @@ -91,26 +95,80 @@ pub trait Iterator { /// An upper bound of `None` means either there is no known upper bound, or the upper bound /// does not fit within a `uint`. #[inline] + #[stable] fn size_hint(&self) -> (uint, Option) { (0, None) } } /// Conversion from an `Iterator` -#[unstable = "may be replaced by a more general conversion trait"] +#[stable] pub trait FromIterator { /// Build a container with elements from an external iterator. fn from_iter>(iterator: T) -> Self; } /// A type growable from an `Iterator` implementation -#[unstable = "just renamed as part of collections reform"] +#[stable] pub trait Extend { /// Extend a container with the elements yielded by an arbitrary iterator fn extend>(&mut self, iterator: T); } -#[unstable = "new convention for extension traits"] /// An extension trait providing numerous methods applicable to all iterators. +#[stable] pub trait IteratorExt: Iterator + Sized { + /// Counts the number of elements in this iterator. + /// + /// # Example + /// + /// ```rust + /// let a = [1i, 2, 3, 4, 5]; + /// let mut it = a.iter(); + /// assert!(it.count() == 5); + /// ``` + #[inline] + #[stable] + fn count(self) -> uint { + self.fold(0, |cnt, _x| cnt + 1) + } + + /// Loops through the entire iterator, returning the last element of the + /// iterator. + /// + /// # Example + /// + /// ```rust + /// let a = [1i, 2, 3, 4, 5]; + /// assert!(a.iter().last().unwrap() == &5); + /// ``` + #[inline] + #[stable] + fn last(mut self) -> Option< ::Item> { + let mut last = None; + for x in self { last = Some(x); } + last + } + + /// Loops through `n` iterations, returning the `n`th element of the + /// iterator. + /// + /// # Example + /// + /// ```rust + /// let a = [1i, 2, 3, 4, 5]; + /// let mut it = a.iter(); + /// assert!(it.nth(2).unwrap() == &3); + /// assert!(it.nth(2) == None); + /// ``` + #[inline] + #[stable] + fn nth(&mut self, mut n: uint) -> Option< ::Item> { + for x in *self { + if n == 0 { return Some(x) } + n -= 1; + } + None + } + /// Chain this iterator with another, returning a new iterator that will /// finish iterating over the current iterator, and then iterate /// over the other specified iterator. @@ -169,7 +227,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(it.next().is_none()); /// ``` #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn map(self, f: F) -> Map< ::Item, B, Self, F> where F: FnMut(::Item) -> B, { @@ -189,7 +247,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(it.next().is_none()); /// ``` #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn filter

(self, predicate: P) -> Filter< ::Item, Self, P> where P: FnMut(&::Item) -> bool, { @@ -209,7 +267,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(it.next().is_none()); /// ``` #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn filter_map(self, f: F) -> FilterMap< ::Item, B, Self, F> where F: FnMut(::Item) -> Option, { @@ -258,9 +316,9 @@ pub trait IteratorExt: Iterator + Sized { Peekable{iter: self, peeked: None} } - /// Creates an iterator that invokes the predicate on elements until it - /// returns false. Once the predicate returns false, all further elements are - /// yielded. + /// Creates an iterator that invokes the predicate on elements + /// until it returns false. Once the predicate returns false, that + /// element and all further elements are yielded. /// /// # Example /// @@ -273,7 +331,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(it.next().is_none()); /// ``` #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn skip_while

(self, predicate: P) -> SkipWhile< ::Item, Self, P> where P: FnMut(&::Item) -> bool, { @@ -294,7 +352,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(it.next().is_none()); /// ``` #[inline] - #[unstable = "waiting for unboxed closures, may want to require peek"] + #[stable] fn take_while

(self, predicate: P) -> TakeWhile< ::Item, Self, P> where P: FnMut(&::Item) -> bool, { @@ -359,7 +417,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(it.next().is_none()); /// ``` #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn scan( self, initial_state: St, @@ -389,7 +447,7 @@ pub trait IteratorExt: Iterator + Sized { /// } /// ``` #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn flat_map(self, f: F) -> FlatMap< ::Item, B, Self, U, F> where U: Iterator, F: FnMut(::Item) -> U, @@ -449,7 +507,7 @@ pub trait IteratorExt: Iterator + Sized { /// println!("{}", sum); /// ``` #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn inspect(self, f: F) -> Inspect< ::Item, Self, F> where F: FnMut(&::Item), { @@ -487,7 +545,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(a.as_slice() == b.as_slice()); /// ``` #[inline] - #[unstable = "waiting for general conversion traits, just changed to take self by value"] + #[stable] fn collect::Item>>(self) -> B { FromIterator::from_iter(self) } @@ -570,7 +628,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(a.iter().fold(0, |a, &b| a + b) == 15); /// ``` #[inline] - #[unstable = "waiting for unboxed closures, just changed to take self by value"] + #[stable] fn fold(mut self, init: B, mut f: F) -> B where F: FnMut(B, ::Item) -> B, { @@ -606,7 +664,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(!a.iter().all(|x| *x > 2)); /// ``` #[inline] - #[unstable = "waiting for unboxed closures, just changed to take self by value"] + #[stable] fn all(mut self, mut f: F) -> bool where F: FnMut(::Item) -> bool { for x in self { if !f(x) { return false; } } true @@ -624,7 +682,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert!(!it.any(|x| *x == 3)); /// ``` #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn any(&mut self, mut f: F) -> bool where F: FnMut(::Item) -> bool { for x in *self { if f(x) { return true; } } false @@ -634,7 +692,7 @@ pub trait IteratorExt: Iterator + Sized { /// /// Does not consume the iterator past the first found element. #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn find

(&mut self, mut predicate: P) -> Option< ::Item> where P: FnMut(&::Item) -> bool, { @@ -646,7 +704,7 @@ pub trait IteratorExt: Iterator + Sized { /// Return the index of the first element satisfying the specified predicate #[inline] - #[unstable = "waiting for unboxed closures"] + #[stable] fn position

(&mut self, mut predicate: P) -> Option where P: FnMut(::Item) -> bool, { @@ -660,6 +718,145 @@ pub trait IteratorExt: Iterator + Sized { None } + /// Return the index of the last element satisfying the specified predicate + /// + /// If no element matches, None is returned. + #[inline] + #[stable] + fn rposition

(&mut self, mut predicate: P) -> Option where + P: FnMut(::Item) -> bool, + Self: ExactSizeIterator + DoubleEndedIterator + { + let len = self.len(); + for i in range(0, len).rev() { + if predicate(self.next_back().expect("rposition: incorrect ExactSizeIterator")) { + return Some(i); + } + } + None + } + + /// Consumes the entire iterator to return the maximum element. + /// + /// # Example + /// + /// ```rust + /// let a = [1i, 2, 3, 4, 5]; + /// assert!(a.iter().max().unwrap() == &5); + /// ``` + #[inline] + #[stable] + fn max(self) -> Option< ::Item> where + ::Item: Ord + { + self.fold(None, |max, x| { + match max { + None => Some(x), + Some(y) => Some(cmp::max(x, y)) + } + }) + } + + /// Consumes the entire iterator to return the minimum element. + /// + /// # Example + /// + /// ```rust + /// let a = [1i, 2, 3, 4, 5]; + /// assert!(a.iter().min().unwrap() == &1); + /// ``` + #[inline] + #[stable] + fn min(self) -> Option< ::Item> where + ::Item: Ord + { + self.fold(None, |min, x| { + match min { + None => Some(x), + Some(y) => Some(cmp::min(x, y)) + } + }) + } + + /// `min_max` finds the minimum and maximum elements in the iterator. + /// + /// The return type `MinMaxResult` is an enum of three variants: + /// + /// - `NoElements` if the iterator is empty. + /// - `OneElement(x)` if the iterator has exactly one element. + /// - `MinMax(x, y)` is returned otherwise, where `x <= y`. Two + /// values are equal if and only if there is more than one + /// element in the iterator and all elements are equal. + /// + /// On an iterator of length `n`, `min_max` does `1.5 * n` comparisons, + /// and so is faster than calling `min` and `max` separately which does `2 * n` comparisons. + /// + /// # Example + /// + /// ```rust + /// use std::iter::MinMaxResult::{NoElements, OneElement, MinMax}; + /// + /// let v: [int; 0] = []; + /// assert_eq!(v.iter().min_max(), NoElements); + /// + /// let v = [1i]; + /// assert!(v.iter().min_max() == OneElement(&1)); + /// + /// let v = [1i, 2, 3, 4, 5]; + /// assert!(v.iter().min_max() == MinMax(&1, &5)); + /// + /// let v = [1i, 2, 3, 4, 5, 6]; + /// assert!(v.iter().min_max() == MinMax(&1, &6)); + /// + /// let v = [1i, 1, 1, 1]; + /// assert!(v.iter().min_max() == MinMax(&1, &1)); + /// ``` + #[unstable = "return type may change"] + fn min_max(mut self) -> MinMaxResult< ::Item> where + ::Item: Ord + { + let (mut min, mut max) = match self.next() { + None => return NoElements, + Some(x) => { + match self.next() { + None => return OneElement(x), + Some(y) => if x < y {(x, y)} else {(y,x)} + } + } + }; + + loop { + // `first` and `second` are the two next elements we want to look at. + // We first compare `first` and `second` (#1). The smaller one is then compared to + // current minimum (#2). The larger one is compared to current maximum (#3). This + // way we do 3 comparisons for 2 elements. + let first = match self.next() { + None => break, + Some(x) => x + }; + let second = match self.next() { + None => { + if first < min { + min = first; + } else if first > max { + max = first; + } + break; + } + Some(x) => x + }; + if first < second { + if first < min {min = first;} + if max < second {max = second;} + } else { + if second < min {min = second;} + if max < first {max = first;} + } + } + + MinMax(min, max) + } + /// Return the element that gives the maximum value from the /// specified function. /// @@ -672,7 +869,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10); /// ``` #[inline] - #[unstable = "waiting for unboxed closures, just changed to take self by value"] + #[unstable = "may want to produce an Ordering directly; see #15311"] fn max_by(self, mut f: F) -> Option< ::Item> where F: FnMut(&::Item) -> B, { @@ -701,7 +898,7 @@ pub trait IteratorExt: Iterator + Sized { /// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0); /// ``` #[inline] - #[unstable = "waiting for unboxed closures, just changed to take self by value"] + #[unstable = "may want to produce an Ordering directly; see #15311"] fn min_by(self, mut f: F) -> Option< ::Item> where F: FnMut(&::Item) -> B, { @@ -740,6 +937,7 @@ pub trait IteratorExt: Iterator + Sized { /// /// Loops through the entire iterator, collecting the first component of /// each item into one new container, and the second component into another. + #[unstable = "recent addition"] fn unzip(mut self) -> (FromA, FromB) where FromA: Default + Extend, FromB: Default + Extend, @@ -769,36 +967,41 @@ pub trait IteratorExt: Iterator + Sized { (ts, us) } -} -#[unstable = "trait is unstable"] -impl IteratorExt for I where I: Iterator {} + /// Creates an iterator that clones the elements it yields. Useful for converting an + /// Iterator<&T> to an Iterator. + #[unstable = "recent addition"] + fn cloned(self) -> Cloned where + Self: Iterator, + D: Deref, + T: Clone, + { + Cloned { it: self } + } -/// A range iterator able to yield elements from both ends -/// -/// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust -/// elements from the *same* range, and do not work independently of each other. -#[unstable = "recently split into two traits"] -pub trait DoubleEndedIterator: Iterator { - /// Yield an element from the end of the range, returning `None` if the range is empty. - fn next_back(&mut self) -> Option< ::Item>; -} + /// Repeats an iterator endlessly + /// + /// # Example + /// + /// ```rust + /// use std::iter::count; + /// + /// let a = count(1i,1i).take(1); + /// let mut cy = a.cycle(); + /// assert_eq!(cy.next(), Some(1)); + /// assert_eq!(cy.next(), Some(1)); + /// ``` + #[stable] + #[inline] + fn cycle(self) -> Cycle where Self: Clone { + Cycle{orig: self.clone(), iter: self} + } -/// A double-ended iterator yielding mutable references -#[experimental = "not widely used"] -pub trait MutableDoubleEndedIterator { - // FIXME: #5898: should be called `reverse` - /// Use an iterator to reverse a container in-place - fn reverse_(&mut self); -} - -#[experimental = "trait is experimental"] -impl<'a, T:'a, I> MutableDoubleEndedIterator for I where - I: DoubleEndedIterator + Iterator, -{ - // FIXME: #5898: should be called `reverse` - /// Use an iterator to reverse a container in-place - fn reverse_(&mut self) { + /// Use an iterator to reverse a container in place. + #[experimental = "uncertain about placement or widespread use"] + fn reverse_in_place<'a, T: 'a>(&mut self) where + Self: Iterator + DoubleEndedIterator + { loop { match (self.next(), self.next_back()) { (Some(x), Some(y)) => mem::swap(x, y), @@ -808,6 +1011,18 @@ impl<'a, T:'a, I> MutableDoubleEndedIterator for I where } } +#[stable] +impl IteratorExt for I where I: Iterator {} + +/// A range iterator able to yield elements from both ends +/// +/// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust +/// elements from the *same* range, and do not work independently of each other. +#[stable] +pub trait DoubleEndedIterator: Iterator { + /// Yield an element from the end of the range, returning `None` if the range is empty. + fn next_back(&mut self) -> Option< ::Item>; +} /// An object implementing random access indexing by `uint` /// @@ -832,24 +1047,8 @@ pub trait RandomAccessIterator: Iterator { /// /// `Iterator::size_hint` *must* return the exact size of the iterator. /// Note that the size must fit in `uint`. -#[unstable = "could move DoubleEndedIterator bound onto rposition with method-level where clauses"] -pub trait ExactSizeIterator: DoubleEndedIterator { - /// Return the index of the last element satisfying the specified predicate - /// - /// If no element matches, None is returned. - #[inline] - fn rposition

(&mut self, mut predicate: P) -> Option where - P: FnMut(::Item) -> bool, - { - let len = self.len(); - for i in range(0, len).rev() { - if predicate(self.next_back().expect("rposition: incorrect ExactSizeIterator")) { - return Some(i); - } - } - None - } - +#[stable] +pub trait ExactSizeIterator: Iterator { #[inline] /// Return the exact length of the iterator. fn len(&self) -> uint { @@ -865,21 +1064,21 @@ pub trait ExactSizeIterator: DoubleEndedIterator { // All adaptors that preserve the size of the wrapped iterator are fine // Adaptors that may overflow in `size_hint` are not, i.e. `Chain`. -#[unstable = "trait is unstable"] +#[stable] impl ExactSizeIterator for Enumerate where I: ExactSizeIterator {} -#[unstable = "trait is unstable"] +#[stable] impl ExactSizeIterator for Inspect where I: ExactSizeIterator + Iterator, F: FnMut(&A), {} -#[unstable = "trait is unstable"] -impl ExactSizeIterator for Rev where I: ExactSizeIterator {} -#[unstable = "trait is unstable"] +#[stable] +impl ExactSizeIterator for Rev where I: ExactSizeIterator + DoubleEndedIterator {} +#[stable] impl ExactSizeIterator for Map where I: ExactSizeIterator + Iterator, F: FnMut(A) -> B, {} -#[unstable = "trait is unstable"] +#[stable] impl ExactSizeIterator for Zip where A: ExactSizeIterator, B: ExactSizeIterator {} /// An double-ended iterator with the direction inverted @@ -890,7 +1089,7 @@ pub struct Rev { iter: T } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Rev where I: DoubleEndedIterator { type Item = ::Item; @@ -900,7 +1099,7 @@ impl Iterator for Rev where I: DoubleEndedIterator { fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } -#[unstable = "trait is unstable"] +#[stable] impl DoubleEndedIterator for Rev where I: DoubleEndedIterator { #[inline] fn next_back(&mut self) -> Option< ::Item> { self.iter.next() } @@ -924,7 +1123,7 @@ pub struct ByRef<'a, I:'a> { iter: &'a mut I, } -#[unstable = "trait is unstable"] +#[stable] impl<'a, I> Iterator for ByRef<'a, I> where I: 'a + Iterator { type Item = ::Item; @@ -934,7 +1133,7 @@ impl<'a, I> Iterator for ByRef<'a, I> where I: 'a + Iterator { fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } -#[unstable = "trait is unstable"] +#[stable] impl<'a, I> DoubleEndedIterator for ByRef<'a, I> where I: 'a + DoubleEndedIterator { #[inline] fn next_back(&mut self) -> Option< ::Item> { self.iter.next_back() } @@ -1025,134 +1224,9 @@ impl_multiplicative! { uint, 1 } impl_multiplicative! { f32, 1.0 } impl_multiplicative! { f64, 1.0 } -/// A trait for iterators over elements which can be compared to one another. -#[unstable = "recently renamed for new extension trait conventions"] -pub trait IteratorOrdExt { - /// Consumes the entire iterator to return the maximum element. - /// - /// # Example - /// - /// ```rust - /// let a = [1, 2, 3, 4, 5]; - /// assert!(a.iter().max().unwrap() == &5); - /// ``` - fn max(self) -> Option; - - /// Consumes the entire iterator to return the minimum element. - /// - /// # Example - /// - /// ```rust - /// let a = [1, 2, 3, 4, 5]; - /// assert!(a.iter().min().unwrap() == &1); - /// ``` - fn min(self) -> Option; - - /// `min_max` finds the minimum and maximum elements in the iterator. - /// - /// The return type `MinMaxResult` is an enum of three variants: - /// - /// - `NoElements` if the iterator is empty. - /// - `OneElement(x)` if the iterator has exactly one element. - /// - `MinMax(x, y)` is returned otherwise, where `x <= y`. Two - /// values are equal if and only if there is more than one - /// element in the iterator and all elements are equal. - /// - /// On an iterator of length `n`, `min_max` does `1.5 * n` comparisons, - /// and so is faster than calling `min` and `max` separately which does `2 * n` comparisons. - /// - /// # Example - /// - /// ```rust - /// use std::iter::MinMaxResult::{NoElements, OneElement, MinMax}; - /// - /// let v: [int; 0] = []; - /// assert_eq!(v.iter().min_max(), NoElements); - /// - /// let v = [1]; - /// assert!(v.iter().min_max() == OneElement(&1)); - /// - /// let v = [1, 2, 3, 4, 5]; - /// assert!(v.iter().min_max() == MinMax(&1, &5)); - /// - /// let v = [1, 2, 3, 4, 5, 6]; - /// assert!(v.iter().min_max() == MinMax(&1, &6)); - /// - /// let v = [1, 1, 1, 1]; - /// assert!(v.iter().min_max() == MinMax(&1, &1)); - /// ``` - fn min_max(self) -> MinMaxResult; -} - -#[unstable = "trait is unstable"] -impl IteratorOrdExt for I where I: Iterator, T: Ord { - #[inline] - fn max(self) -> Option { - self.fold(None, |max, x| { - match max { - None => Some(x), - Some(y) => Some(cmp::max(x, y)) - } - }) - } - - #[inline] - fn min(self) -> Option { - self.fold(None, |min, x| { - match min { - None => Some(x), - Some(y) => Some(cmp::min(x, y)) - } - }) - } - - fn min_max(mut self) -> MinMaxResult { - let (mut min, mut max) = match self.next() { - None => return NoElements, - Some(x) => { - match self.next() { - None => return OneElement(x), - Some(y) => if x < y {(x, y)} else {(y,x)} - } - } - }; - - loop { - // `first` and `second` are the two next elements we want to look at. - // We first compare `first` and `second` (#1). The smaller one is then compared to - // current minimum (#2). The larger one is compared to current maximum (#3). This - // way we do 3 comparisons for 2 elements. - let first = match self.next() { - None => break, - Some(x) => x - }; - let second = match self.next() { - None => { - if first < min { - min = first; - } else if first > max { - max = first; - } - break; - } - Some(x) => x - }; - if first < second { - if first < min {min = first;} - if max < second {max = second;} - } else { - if second < min {min = second;} - if max < first {max = first;} - } - } - - MinMax(min, max) - } -} - /// `MinMaxResult` is an enum returned by `min_max`. See `IteratorOrdExt::min_max` for more detail. #[derive(Clone, PartialEq, Show)] -#[unstable = "waiting on namespaced enum conventions"] +#[unstable = "unclear whether such a fine-grained result is widely useful"] pub enum MinMaxResult { /// Empty iterator NoElements, @@ -1164,7 +1238,6 @@ pub enum MinMaxResult { MinMax(T, T) } -#[stable] impl MinMaxResult { /// `into_option` creates an `Option` of type `(T,T)`. The returned `Option` has variant /// `None` if and only if the `MinMaxResult` has variant `NoElements`. Otherwise variant @@ -1185,6 +1258,7 @@ impl MinMaxResult { /// let r = MinMax(1, 2); /// assert_eq!(r.into_option(), Some((1,2))); /// ``` + #[unstable = "type is unstable"] pub fn into_option(self) -> Option<(T,T)> { match self { NoElements => None, @@ -1194,30 +1268,15 @@ impl MinMaxResult { } } -/// A trait for iterators that contain cloneable elements -#[unstable = "recently renamed for extension trait conventions"] -pub trait IteratorCloneExt { - /// Creates an iterator that clones the elements it yields. Useful for converting an - /// Iterator<&T> to an Iterator. - fn cloned(self) -> Cloned; -} - -#[unstable = "trait is unstable"] -impl IteratorCloneExt for I where - T: Clone, - D: Deref, - I: Iterator, -{ - fn cloned(self) -> Cloned { - Cloned { it: self } - } -} - /// An iterator that clones the elements of an underlying iterator +#[unstable = "recent addition"] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] +#[derive(Clone)] pub struct Cloned { it: I, } +#[stable] impl Iterator for Cloned where T: Clone, D: Deref, @@ -1234,6 +1293,7 @@ impl Iterator for Cloned where } } +#[stable] impl DoubleEndedIterator for Cloned where T: Clone, D: Deref, @@ -1244,39 +1304,13 @@ impl DoubleEndedIterator for Cloned where } } -#[unstable = "trait is unstable"] +#[stable] impl ExactSizeIterator for Cloned where T: Clone, D: Deref, I: ExactSizeIterator + Iterator, {} -#[unstable = "recently renamed for extension trait conventions"] -/// An extension trait for cloneable iterators. -pub trait CloneIteratorExt { - /// Repeats an iterator endlessly - /// - /// # Example - /// - /// ```rust - /// use std::iter::{CloneIteratorExt, count}; - /// - /// let a = count(1, 1).take(1); - /// let mut cy = a.cycle(); - /// assert_eq!(cy.next(), Some(1)); - /// assert_eq!(cy.next(), Some(1)); - /// ``` - #[stable] - fn cycle(self) -> Cycle; -} - -impl CloneIteratorExt for I where I: Iterator + Clone { - #[inline] - fn cycle(self) -> Cycle { - Cycle{orig: self.clone(), iter: self} - } -} - /// An iterator that repeats endlessly #[derive(Clone, Copy)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] @@ -1286,6 +1320,7 @@ pub struct Cycle { iter: I, } +#[stable] impl Iterator for Cycle where I: Clone + Iterator { type Item = ::Item; @@ -1345,7 +1380,7 @@ pub struct Chain { flag: bool, } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Chain where A: Iterator, B: Iterator { type Item = T; @@ -1379,7 +1414,7 @@ impl Iterator for Chain where A: Iterator, B: Iterator DoubleEndedIterator for Chain where A: DoubleEndedIterator + Iterator, B: DoubleEndedIterator + Iterator, @@ -1424,7 +1459,7 @@ pub struct Zip { b: B } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Zip where A: Iterator, B: Iterator, @@ -1460,10 +1495,10 @@ impl Iterator for Zip where } } -#[unstable = "trait is unstable"] +#[stable] impl DoubleEndedIterator for Zip where - A: ExactSizeIterator + Iterator, - B: ExactSizeIterator + Iterator, + A: ExactSizeIterator + Iterator + DoubleEndedIterator, + B: ExactSizeIterator + Iterator + DoubleEndedIterator, { #[inline] fn next_back(&mut self) -> Option<(T, U)> { @@ -1539,7 +1574,7 @@ impl Map where I: Iterator, F: FnMut(A) -> B { } } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Map where I: Iterator, F: FnMut(A) -> B { type Item = B; @@ -1555,7 +1590,7 @@ impl Iterator for Map where I: Iterator, F: FnMu } } -#[unstable = "trait is unstable"] +#[stable] impl DoubleEndedIterator for Map where I: DoubleEndedIterator + Iterator, F: FnMut(A) -> B, @@ -1606,7 +1641,7 @@ impl Clone for Filter where } } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Filter where I: Iterator, P: FnMut(&A) -> bool { type Item = A; @@ -1629,7 +1664,7 @@ impl Iterator for Filter where I: Iterator, P: FnMut(& } } -#[unstable = "trait is unstable"] +#[stable] impl DoubleEndedIterator for Filter where I: DoubleEndedIterator + Iterator, P: FnMut(&A) -> bool, @@ -1667,7 +1702,7 @@ impl Clone for FilterMap where } } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for FilterMap where I: Iterator, F: FnMut(A) -> Option, @@ -1692,7 +1727,7 @@ impl Iterator for FilterMap where } } -#[unstable = "trait is unstable"] +#[stable] impl DoubleEndedIterator for FilterMap where I: DoubleEndedIterator + Iterator, F: FnMut(A) -> Option, @@ -1718,7 +1753,7 @@ pub struct Enumerate { count: uint } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Enumerate where I: Iterator { type Item = (uint, ::Item); @@ -1740,8 +1775,10 @@ impl Iterator for Enumerate where I: Iterator { } } -#[unstable = "trait is unstable"] -impl DoubleEndedIterator for Enumerate where I: ExactSizeIterator { +#[stable] +impl DoubleEndedIterator for Enumerate where + I: ExactSizeIterator + DoubleEndedIterator +{ #[inline] fn next_back(&mut self) -> Option<(uint, ::Item)> { match self.iter.next_back() { @@ -1779,6 +1816,7 @@ pub struct Peekable where I: Iterator { peeked: Option, } +#[stable] impl Iterator for Peekable where I: Iterator { type Item = T; @@ -1850,7 +1888,7 @@ impl Clone for SkipWhile where } } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for SkipWhile where I: Iterator, P: FnMut(&A) -> bool { type Item = A; @@ -1896,7 +1934,7 @@ impl Clone for TakeWhile where } } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for TakeWhile where I: Iterator, P: FnMut(&A) -> bool { type Item = A; @@ -1935,7 +1973,7 @@ pub struct Skip { n: uint } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Skip where I: Iterator { type Item = ::Item; @@ -2005,7 +2043,7 @@ pub struct Take { n: uint } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Take where I: Iterator{ type Item = ::Item; @@ -2054,7 +2092,7 @@ impl RandomAccessIterator for Take where I: RandomAccessIterator{ /// An iterator to maintain state while iterating another iterator #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] -#[unstable = "waiting for unboxed closures"] +#[stable] pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Option { iter: I, f: F, @@ -2079,7 +2117,7 @@ impl Clone for Scan where } } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Scan where I: Iterator, F: FnMut(&mut St, A) -> Option, @@ -2102,7 +2140,7 @@ impl Iterator for Scan where /// and yields the elements of the produced iterators /// #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] -#[unstable = "waiting for unboxed closures"] +#[stable] pub struct FlatMap where I: Iterator, U: Iterator, @@ -2131,7 +2169,7 @@ impl Clone for FlatMap where } } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for FlatMap where I: Iterator, U: Iterator, @@ -2166,7 +2204,7 @@ impl Iterator for FlatMap where } } -#[unstable = "trait is unstable"] +#[stable] impl DoubleEndedIterator for FlatMap where I: DoubleEndedIterator + Iterator, U: DoubleEndedIterator + Iterator, @@ -2199,7 +2237,7 @@ pub struct Fuse { done: bool } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Fuse where I: Iterator { type Item = ::Item; @@ -2228,7 +2266,7 @@ impl Iterator for Fuse where I: Iterator { } } -#[unstable = "trait is unstable"] +#[stable] impl DoubleEndedIterator for Fuse where I: DoubleEndedIterator { #[inline] fn next_back(&mut self) -> Option< ::Item> { @@ -2260,11 +2298,11 @@ impl RandomAccessIterator for Fuse where I: RandomAccessIterator { } } -#[experimental = "seems marginal"] impl Fuse { /// Resets the fuse such that the next call to .next() or .next_back() will /// call the underlying iterator again even if it previously returned None. #[inline] + #[experimental = "seems marginal"] pub fn reset_fuse(&mut self) { self.done = false } @@ -2273,7 +2311,7 @@ impl Fuse { /// An iterator that calls a function with a reference to each /// element before yielding it. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] -#[unstable = "waiting for unboxed closures"] +#[stable] pub struct Inspect where I: Iterator, F: FnMut(&A) { iter: I, f: F, @@ -2305,7 +2343,7 @@ impl Inspect where I: Iterator, F: FnMut(&A) { } } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Inspect where I: Iterator, F: FnMut(&A) { type Item = A; @@ -2321,7 +2359,7 @@ impl Iterator for Inspect where I: Iterator, F: FnMut( } } -#[unstable = "trait is unstable"] +#[stable] impl DoubleEndedIterator for Inspect where I: DoubleEndedIterator + Iterator, F: FnMut(&A), @@ -2416,7 +2454,7 @@ impl Unfold where F: FnMut(&mut St) -> Option { } } -#[experimental] +#[stable] impl Iterator for Unfold where F: FnMut(&mut St) -> Option { type Item = A; @@ -2435,7 +2473,7 @@ impl Iterator for Unfold where F: FnMut(&mut St) -> Option { /// The current state the counter is at (next value to be yielded) state: A, @@ -2445,12 +2483,12 @@ pub struct Counter { /// Creates a new counter with the specified start/step #[inline] -#[unstable = "may be renamed"] +#[unstable = "may be renamed or replaced by range notation adapaters"] pub fn count(start: A, step: A) -> Counter { Counter{state: start, step: step} } -#[unstable = "trait is unstable"] +#[stable] impl + Clone> Iterator for Counter { type Item = A; @@ -2469,7 +2507,7 @@ impl + Clone> Iterator for Counter { /// An iterator over the range [start, stop) #[derive(Clone, Copy)] -#[unstable = "may be refactored due to numerics reform or ops reform"] +#[unstable = "will be replaced by range notation"] pub struct Range { state: A, stop: A, @@ -2490,6 +2528,7 @@ pub struct Range { /// } /// ``` #[inline] +#[unstable = "will be replaced by range notation"] pub fn range(start: A, stop: A) -> Range { Range { state: start, @@ -2499,7 +2538,7 @@ pub fn range(start: A, stop: A) -> Range { } // FIXME: #10414: Unfortunate type bound -#[unstable = "trait is unstable"] +#[unstable = "will be replaced by range notation"] impl Iterator for Range { type Item = A; @@ -2549,7 +2588,7 @@ impl Iterator for Range { /// `Int` is required to ensure the range will be the same regardless of /// the direction it is consumed. -#[unstable = "trait is unstable"] +#[unstable = "will be replaced by range notation"] impl DoubleEndedIterator for Range { #[inline] fn next_back(&mut self) -> Option { @@ -2564,7 +2603,7 @@ impl DoubleEndedIterator for Range { /// An iterator over the range [start, stop] #[derive(Clone)] -#[unstable = "may be refactored due to numerics reform or ops reform"] +#[unstable = "likely to be replaced by range notation and adapters"] pub struct RangeInclusive { range: Range, done: bool, @@ -2572,7 +2611,7 @@ pub struct RangeInclusive { /// Return an iterator over the range [start, stop] #[inline] -#[unstable = "may be refactored due to numerics reform or ops reform"] +#[unstable = "likely to be replaced by range notation and adapters"] pub fn range_inclusive(start: A, stop: A) -> RangeInclusive { RangeInclusive { range: range(start, stop), @@ -2580,7 +2619,7 @@ pub fn range_inclusive(start: A, stop: A) -> RangeInclusive { } } -#[unstable = "trait is unstable"] +#[unstable = "likely to be replaced by range notation and adapters"] impl Iterator for RangeInclusive { type Item = A; @@ -2615,7 +2654,7 @@ impl Iterator for RangeInclusive { } } -#[unstable = "trait is unstable"] +#[unstable = "likely to be replaced by range notation and adapters"] impl DoubleEndedIterator for RangeInclusive { #[inline] fn next_back(&mut self) -> Option { @@ -2634,7 +2673,7 @@ impl DoubleEndedIterator for RangeInclusive { /// An iterator over the range [start, stop) by `step`. It handles overflow by stopping. #[derive(Clone)] -#[unstable = "may be refactored due to numerics reform or ops reform"] +#[unstable = "likely to be replaced by range notation and adapters"] pub struct RangeStep { state: A, stop: A, @@ -2644,13 +2683,13 @@ pub struct RangeStep { /// Return an iterator over the range [start, stop) by `step`. It handles overflow by stopping. #[inline] -#[unstable = "may be refactored due to numerics reform or ops reform"] +#[unstable = "likely to be replaced by range notation and adapters"] pub fn range_step(start: A, stop: A, step: A) -> RangeStep { let rev = step < Int::zero(); RangeStep{state: start, stop: stop, step: step, rev: rev} } -#[unstable = "trait is unstable"] +#[unstable = "likely to be replaced by range notation and adapters"] impl Iterator for RangeStep { type Item = A; @@ -2671,7 +2710,7 @@ impl Iterator for RangeStep { /// An iterator over the range [start, stop] by `step`. It handles overflow by stopping. #[derive(Clone)] -#[unstable = "may be refactored due to numerics reform or ops reform"] +#[unstable = "likely to be replaced by range notation and adapters"] pub struct RangeStepInclusive { state: A, stop: A, @@ -2682,7 +2721,7 @@ pub struct RangeStepInclusive { /// Return an iterator over the range [start, stop] by `step`. It handles overflow by stopping. #[inline] -#[unstable = "may be refactored due to numerics reform or ops reform"] +#[unstable = "likely to be replaced by range notation and adapters"] pub fn range_step_inclusive(start: A, stop: A, step: A) -> RangeStepInclusive { let rev = step < Int::zero(); RangeStepInclusive { @@ -2694,7 +2733,7 @@ pub fn range_step_inclusive(start: A, stop: A, step: A) -> RangeStepIncl } } -#[unstable = "trait is unstable"] +#[unstable = "likely to be replaced by range notation and adapters"] impl Iterator for RangeStepInclusive { type Item = A; @@ -2719,7 +2758,7 @@ impl Iterator for RangeStepInclusive { /// directions. The `steps_between` function provides a way to /// compare two Step objects (it could be provided using `step()` and `Ord`, /// but the implementation would be so inefficient as to be useless). -#[unstable = "Trait is unstable."] +#[unstable = "design of range notation/iteration is in flux"] pub trait Step: Ord { /// Change self to the next object. fn step(&mut self); @@ -2779,7 +2818,7 @@ pub struct Repeat { element: A } -#[unstable = "trait is unstable"] +#[stable] impl Iterator for Repeat { type Item = A; @@ -2789,7 +2828,7 @@ impl Iterator for Repeat { fn size_hint(&self) -> (uint, Option) { (uint::MAX, None) } } -#[unstable = "trait is unstable"] +#[stable] impl DoubleEndedIterator for Repeat { #[inline] fn next_back(&mut self) -> Option { self.idx(0) } @@ -2855,7 +2894,7 @@ pub fn repeat(elt: T) -> Repeat { /// /// If two sequences are equal up until the point where one ends, /// the shorter sequence compares less. -#[experimental = "likely to be removed after cmp reform"] +#[unstable = "needs review and revision"] pub mod order { use cmp; use cmp::{Eq, Ord, PartialOrd, PartialEq}; diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 17e4c5f8215..3d4be651f83 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -59,6 +59,8 @@ //! See the documentation for each trait for a minimum implementation that prints //! something to the screen. +#![stable] + use clone::Clone; use iter::{Step, Iterator,DoubleEndedIterator,ExactSizeIterator}; use kinds::Sized; @@ -86,8 +88,10 @@ use option::Option::{self, Some, None}; /// } /// ``` #[lang="drop"] +#[stable] pub trait Drop { /// The `drop` method, called when the value goes out of scope. + #[stable] fn drop(&mut self); } @@ -120,15 +124,19 @@ pub trait Drop { /// } /// ``` #[lang="add"] +#[stable] pub trait Add { + #[stable] type Output; /// The method for the `+` operator + #[stable] fn add(self, rhs: RHS) -> Self::Output; } macro_rules! add_impl { ($($t:ty)*) => ($( + #[stable] impl Add for $t { type Output = $t; @@ -169,15 +177,19 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="sub"] +#[stable] pub trait Sub { + #[stable] type Output; /// The method for the `-` operator + #[stable] fn sub(self, rhs: RHS) -> Self::Output; } macro_rules! sub_impl { ($($t:ty)*) => ($( + #[stable] impl Sub for $t { type Output = $t; @@ -218,15 +230,19 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="mul"] +#[stable] pub trait Mul { + #[stable] type Output; /// The method for the `*` operator + #[stable] fn mul(self, rhs: RHS) -> Self::Output; } macro_rules! mul_impl { ($($t:ty)*) => ($( + #[stable] impl Mul for $t { type Output = $t; @@ -267,15 +283,19 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="div"] +#[stable] pub trait Div { + #[stable] type Output; /// The method for the `/` operator + #[stable] fn div(self, rhs: RHS) -> Self::Output; } macro_rules! div_impl { ($($t:ty)*) => ($( + #[stable] impl Div for $t { type Output = $t; @@ -316,15 +336,19 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="rem"] +#[stable] pub trait Rem { + #[stable] type Output = Self; /// The method for the `%` operator + #[stable] fn rem(self, rhs: RHS) -> Self::Output; } macro_rules! rem_impl { ($($t:ty)*) => ($( + #[stable] impl Rem for $t { type Output = $t; @@ -336,6 +360,7 @@ macro_rules! rem_impl { macro_rules! rem_float_impl { ($t:ty, $fmod:ident) => { + #[stable] impl Rem for $t { type Output = $t; @@ -382,19 +407,25 @@ rem_float_impl! { f64, fmod } /// } /// ``` #[lang="neg"] +#[stable] pub trait Neg { + #[stable] type Output; /// The method for the unary `-` operator + #[stable] fn neg(self) -> Self::Output; } macro_rules! neg_impl { ($($t:ty)*) => ($( + #[stable] impl Neg for $t { + #[stable] type Output = $t; #[inline] + #[stable] fn neg(self) -> $t { -self } } )*) @@ -402,6 +433,7 @@ macro_rules! neg_impl { macro_rules! neg_uint_impl { ($t:ty, $t_signed:ty) => { + #[stable] impl Neg for $t { type Output = $t; @@ -450,15 +482,19 @@ neg_uint_impl! { u64, i64 } /// } /// ``` #[lang="not"] +#[stable] pub trait Not { + #[stable] type Output; /// The method for the unary `!` operator + #[stable] fn not(self) -> Self::Output; } macro_rules! not_impl { ($($t:ty)*) => ($( + #[stable] impl Not for $t { type Output = $t; @@ -499,15 +535,19 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="bitand"] +#[stable] pub trait BitAnd { + #[stable] type Output; /// The method for the `&` operator + #[stable] fn bitand(self, rhs: RHS) -> Self::Output; } macro_rules! bitand_impl { ($($t:ty)*) => ($( + #[stable] impl BitAnd for $t { type Output = $t; @@ -548,15 +588,19 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="bitor"] +#[stable] pub trait BitOr { + #[stable] type Output; /// The method for the `|` operator + #[stable] fn bitor(self, rhs: RHS) -> Self::Output; } macro_rules! bitor_impl { ($($t:ty)*) => ($( + #[stable] impl BitOr for $t { type Output = $t; @@ -597,15 +641,19 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="bitxor"] +#[stable] pub trait BitXor { + #[stable] type Output; /// The method for the `^` operator + #[stable] fn bitxor(self, rhs: RHS) -> Self::Output; } macro_rules! bitxor_impl { ($($t:ty)*) => ($( + #[stable] impl BitXor for $t { type Output = $t; @@ -646,15 +694,19 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="shl"] +#[stable] pub trait Shl { + #[stable] type Output; /// The method for the `<<` operator + #[stable] fn shl(self, rhs: RHS) -> Self::Output; } macro_rules! shl_impl { ($($t:ty)*) => ($( + #[stable] impl Shl for $t { type Output = $t; @@ -697,10 +749,13 @@ shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="shr"] +#[stable] pub trait Shr { + #[stable] type Output; /// The method for the `>>` operator + #[stable] fn shr(self, rhs: RHS) -> Self::Output; } @@ -893,11 +948,13 @@ pub trait SliceMut for Sized? { /// An unbounded range. #[derive(Copy)] #[lang="full_range"] +#[unstable = "API still in development"] pub struct FullRange; /// A (half-open) range which is bounded at both ends. #[derive(Copy)] #[lang="range"] +#[unstable = "API still in development"] pub struct Range { /// The lower bound of the range (inclusive). pub start: Idx, @@ -907,6 +964,7 @@ pub struct Range { // FIXME(#19391) needs a snapshot //impl> Iterator for Range { +#[unstable = "API still in development"] impl Iterator for Range { type Item = Idx; @@ -931,6 +989,7 @@ impl Iterator for Range { } } +#[unstable = "API still in development"] impl DoubleEndedIterator for Range { #[inline] fn next_back(&mut self) -> Option { @@ -943,16 +1002,19 @@ impl DoubleEndedIterator for Range { } } +#[unstable = "API still in development"] impl ExactSizeIterator for Range {} /// A range which is only bounded below. #[derive(Copy)] #[lang="range_from"] +#[unstable = "API still in development"] pub struct RangeFrom { /// The lower bound of the range (inclusive). pub start: Idx, } +#[unstable = "API still in development"] impl Iterator for RangeFrom { type Item = Idx; @@ -968,6 +1030,7 @@ impl Iterator for RangeFrom { /// A range which is only bounded above. #[derive(Copy)] #[lang="range_to"] +#[unstable = "API still in development"] pub struct RangeTo { /// The upper bound of the range (exclusive). pub end: Idx, @@ -1005,19 +1068,24 @@ pub struct RangeTo { /// } /// ``` #[lang="deref"] +#[stable] pub trait Deref for Sized? { + #[stable] type Sized? Target; /// The method called to dereference a value + #[stable] fn deref<'a>(&'a self) -> &'a Self::Target; } +#[stable] impl<'a, Sized? T> Deref for &'a T { type Target = T; fn deref(&self) -> &T { *self } } +#[stable] impl<'a, Sized? T> Deref for &'a mut T { type Target = T; @@ -1062,17 +1130,21 @@ impl<'a, Sized? T> Deref for &'a mut T { /// } /// ``` #[lang="deref_mut"] +#[stable] pub trait DerefMut for Sized? : Deref { /// The method called to mutably dereference a value + #[stable] fn deref_mut<'a>(&'a mut self) -> &'a mut ::Target; } +#[stable] impl<'a, Sized? T> DerefMut for &'a mut T { fn deref_mut(&mut self) -> &mut T { *self } } /// A version of the call operator that takes an immutable receiver. #[lang="fn"] +#[unstable = "uncertain about variadic generics, input versus associated types"] pub trait Fn for Sized? { /// This is called when the call operator is used. extern "rust-call" fn call(&self, args: Args) -> Result; @@ -1080,6 +1152,7 @@ pub trait Fn for Sized? { /// A version of the call operator that takes a mutable receiver. #[lang="fn_mut"] +#[unstable = "uncertain about variadic generics, input versus associated types"] pub trait FnMut for Sized? { /// This is called when the call operator is used. extern "rust-call" fn call_mut(&mut self, args: Args) -> Result; @@ -1087,6 +1160,7 @@ pub trait FnMut for Sized? { /// A version of the call operator that takes a by-value receiver. #[lang="fn_once"] +#[unstable = "uncertain about variadic generics, input versus associated types"] pub trait FnOnce { /// This is called when the call operator is used. extern "rust-call" fn call_once(self, args: Args) -> Result; diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 9e55a3aa8c4..3c96011867c 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -807,6 +807,7 @@ impl ExactSizeIterator for Item {} #[stable] pub struct Iter<'a, A: 'a> { inner: Item<&'a A> } +#[stable] impl<'a, A> Iterator for Iter<'a, A> { type Item = &'a A; @@ -816,11 +817,13 @@ impl<'a, A> Iterator for Iter<'a, A> { fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, A> DoubleEndedIterator for Iter<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a A> { self.inner.next_back() } } +#[stable] impl<'a, A> ExactSizeIterator for Iter<'a, A> {} #[stable] @@ -834,6 +837,7 @@ impl<'a, A> Clone for Iter<'a, A> { #[stable] pub struct IterMut<'a, A: 'a> { inner: Item<&'a mut A> } +#[stable] impl<'a, A> Iterator for IterMut<'a, A> { type Item = &'a mut A; @@ -843,17 +847,20 @@ impl<'a, A> Iterator for IterMut<'a, A> { fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, A> DoubleEndedIterator for IterMut<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a mut A> { self.inner.next_back() } } +#[stable] impl<'a, A> ExactSizeIterator for IterMut<'a, A> {} /// An iterator over the item contained inside an Option. #[stable] pub struct IntoIter { inner: Item } +#[stable] impl Iterator for IntoIter { type Item = A; @@ -863,11 +870,13 @@ impl Iterator for IntoIter { fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.inner.next_back() } } +#[stable] impl ExactSizeIterator for IntoIter {} ///////////////////////////////////////////////////////////////////////////// diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index d4aca1bb73c..e88cb73c8a9 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -43,8 +43,7 @@ pub use clone::Clone; pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; pub use iter::{Extend, IteratorExt}; pub use iter::{Iterator, DoubleEndedIterator}; -pub use iter::{IteratorCloneExt, CloneIteratorExt}; -pub use iter::{IteratorOrdExt, ExactSizeIterator}; +pub use iter::{ExactSizeIterator}; pub use option::Option::{self, Some, None}; pub use ptr::{PtrExt, MutPtrExt}; pub use result::Result::{self, Ok, Err}; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 7135faaa765..7293ed6455b 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -807,6 +807,7 @@ impl AsSlice for Result { #[stable] pub struct Iter<'a, T: 'a> { inner: Option<&'a T> } +#[stable] impl<'a, T> Iterator for Iter<'a, T> { type Item = &'a T; @@ -819,11 +820,13 @@ impl<'a, T> Iterator for Iter<'a, T> { } } +#[stable] impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { self.inner.take() } } +#[stable] impl<'a, T> ExactSizeIterator for Iter<'a, T> {} impl<'a, T> Clone for Iter<'a, T> { @@ -834,6 +837,7 @@ impl<'a, T> Clone for Iter<'a, T> { #[stable] pub struct IterMut<'a, T: 'a> { inner: Option<&'a mut T> } +#[stable] impl<'a, T> Iterator for IterMut<'a, T> { type Item = &'a mut T; @@ -846,17 +850,20 @@ impl<'a, T> Iterator for IterMut<'a, T> { } } +#[stable] impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut T> { self.inner.take() } } +#[stable] impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} /// An iterator over the value in a `Ok` variant of a `Result`. #[stable] pub struct IntoIter { inner: Option } +#[stable] impl Iterator for IntoIter { type Item = T; @@ -869,11 +876,13 @@ impl Iterator for IntoIter { } } +#[stable] impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.inner.take() } } +#[stable] impl ExactSizeIterator for IntoIter {} ///////////////////////////////////////////////////////////////////////////// diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 7aed16173e9..ae88a27974c 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -650,7 +650,7 @@ impl<'a, T> Default for &'a [T] { // The shared definition of the `Iter` and `IterMut` iterators macro_rules! iterator { (struct $name:ident -> $ptr:ty, $elem:ty) => { - #[experimental = "needs review"] + #[stable] impl<'a, T> Iterator for $name<'a, T> { type Item = $elem; @@ -688,7 +688,7 @@ macro_rules! iterator { } } - #[experimental = "needs review"] + #[stable] impl<'a, T> DoubleEndedIterator for $name<'a, T> { #[inline] fn next_back(&mut self) -> Option<$elem> { @@ -771,7 +771,7 @@ impl<'a,T> Copy for Iter<'a,T> {} iterator!{struct Iter -> *const T, &'a T} -#[experimental = "needs review"] +#[stable] impl<'a, T> ExactSizeIterator for Iter<'a, T> {} #[stable] @@ -779,7 +779,7 @@ impl<'a, T> Clone for Iter<'a, T> { fn clone(&self) -> Iter<'a, T> { *self } } -#[experimental = "needs review"] +#[experimental = "trait is experimental"] impl<'a, T> RandomAccessIterator for Iter<'a, T> { #[inline] fn indexable(&self) -> uint { @@ -865,7 +865,7 @@ impl<'a, T> IterMut<'a, T> { iterator!{struct IterMut -> *mut T, &'a mut T} -#[experimental = "needs review"] +#[stable] impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} /// An internal abstraction over the splitting iterators, so that @@ -897,7 +897,7 @@ impl<'a, T, P> Clone for Split<'a, T, P> where P: Clone + FnMut(&T) -> bool { } } -#[experimental = "needs review"] +#[stable] impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool { type Item = &'a [T]; @@ -925,7 +925,7 @@ impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool { } } -#[experimental = "needs review"] +#[stable] impl<'a, T, P> DoubleEndedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { @@ -970,7 +970,7 @@ impl<'a, T, P> SplitIter for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { } } -#[experimental = "needs review"] +#[stable] impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { type Item = &'a mut [T]; @@ -1005,7 +1005,7 @@ impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { } } -#[experimental = "needs review"] +#[stable] impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool, { @@ -1038,7 +1038,6 @@ struct GenericSplitN { invert: bool } -#[experimental = "needs review"] impl> Iterator for GenericSplitN { type Item = T; @@ -1061,6 +1060,7 @@ impl> Iterator for GenericSplitN { /// An iterator over subslices separated by elements that match a predicate /// function, limited to a given number of splits. +#[stable] pub struct SplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } @@ -1068,12 +1068,14 @@ pub struct SplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool { /// An iterator over subslices separated by elements that match a /// predicate function, limited to a given number of splits, starting /// from the end of the slice. +#[stable] pub struct RSplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } /// An iterator over subslices separated by elements that match a predicate /// function, limited to a given number of splits. +#[stable] pub struct SplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } @@ -1081,12 +1083,14 @@ pub struct SplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { /// An iterator over subslices separated by elements that match a /// predicate function, limited to a given number of splits, starting /// from the end of the slice. +#[stable] pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } macro_rules! forward_iterator { ($name:ident: $elem:ident, $iter_of:ty) => { + #[stable] impl<'a, $elem, P> Iterator for $name<'a, $elem, P> where P: FnMut(&T) -> bool { @@ -1112,12 +1116,13 @@ forward_iterator! { RSplitNMut: T, &'a mut [T] } /// An iterator over overlapping subslices of length `size`. #[derive(Clone)] -#[experimental = "needs review"] +#[stable] pub struct Windows<'a, T:'a> { v: &'a [T], size: uint } +#[stable] impl<'a, T> Iterator for Windows<'a, T> { type Item = &'a [T]; @@ -1149,13 +1154,13 @@ impl<'a, T> Iterator for Windows<'a, T> { /// When the slice len is not evenly divided by the chunk size, the last slice /// of the iteration will be the remainder. #[derive(Clone)] -#[experimental = "needs review"] +#[stable] pub struct Chunks<'a, T:'a> { v: &'a [T], size: uint } -#[experimental = "needs review"] +#[stable] impl<'a, T> Iterator for Chunks<'a, T> { type Item = &'a [T]; @@ -1184,7 +1189,7 @@ impl<'a, T> Iterator for Chunks<'a, T> { } } -#[experimental = "needs review"] +#[stable] impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { @@ -1200,7 +1205,7 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { } } -#[experimental = "needs review"] +#[experimental = "trait is experimental"] impl<'a, T> RandomAccessIterator for Chunks<'a, T> { #[inline] fn indexable(&self) -> uint { @@ -1224,13 +1229,13 @@ impl<'a, T> RandomAccessIterator for Chunks<'a, T> { /// An iterator over a slice in (non-overlapping) mutable chunks (`size` /// elements at a time). When the slice len is not evenly divided by the chunk /// size, the last slice of the iteration will be the remainder. -#[experimental = "needs review"] +#[stable] pub struct ChunksMut<'a, T:'a> { v: &'a mut [T], chunk_size: uint } -#[experimental = "needs review"] +#[stable] impl<'a, T> Iterator for ChunksMut<'a, T> { type Item = &'a mut [T]; @@ -1260,7 +1265,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> { } } -#[experimental = "needs review"] +#[stable] impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut [T]> { @@ -1338,7 +1343,7 @@ pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] { /// not being able to provide a non-aliasing guarantee of the returned mutable /// slice. #[inline] -#[unstable = "jshould be renamed to from_raw_parts_mut"] +#[unstable = "should be renamed to from_raw_parts_mut"] pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: uint) -> &'a mut [T] { transmute(RawSlice { data: *p as *const T, len: len }) } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index f93a5114dcf..a30fe68d9c3 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -37,11 +37,8 @@ use uint; macro_rules! delegate_iter { (exact $te:ty in $ti:ty) => { delegate_iter!{$te in $ti} + #[stable] impl<'a> ExactSizeIterator for $ti { - #[inline] - fn rposition

(&mut self, predicate: P) -> Option where P: FnMut($te) -> bool{ - self.0.rposition(predicate) - } #[inline] fn len(&self) -> uint { self.0.len() @@ -49,6 +46,7 @@ macro_rules! delegate_iter { } }; ($te:ty in $ti:ty) => { + #[stable] impl<'a> Iterator for $ti { type Item = $te; @@ -61,6 +59,7 @@ macro_rules! delegate_iter { self.0.size_hint() } } + #[stable] impl<'a> DoubleEndedIterator for $ti { #[inline] fn next_back(&mut self) -> Option<$te> { @@ -69,6 +68,7 @@ macro_rules! delegate_iter { } }; (pattern $te:ty in $ti:ty) => { + #[stable] impl<'a, P: CharEq> Iterator for $ti { type Item = $te; @@ -81,6 +81,7 @@ macro_rules! delegate_iter { self.0.size_hint() } } + #[stable] impl<'a, P: CharEq> DoubleEndedIterator for $ti { #[inline] fn next_back(&mut self) -> Option<$te> { @@ -89,6 +90,7 @@ macro_rules! delegate_iter { } }; (pattern forward $te:ty in $ti:ty) => { + #[stable] impl<'a, P: CharEq> Iterator for $ti { type Item = $te; @@ -275,6 +277,7 @@ fn unwrap_or_0(opt: Option<&u8>) -> u8 { } } +#[stable] impl<'a> Iterator for Chars<'a> { type Item = char; @@ -320,6 +323,7 @@ impl<'a> Iterator for Chars<'a> { } } +#[stable] impl<'a> DoubleEndedIterator for Chars<'a> { #[inline] fn next_back(&mut self) -> Option { @@ -356,11 +360,13 @@ impl<'a> DoubleEndedIterator for Chars<'a> { /// External iterator for a string's characters and their byte offsets. /// Use with the `std::iter` module. #[derive(Clone)] +#[stable] pub struct CharIndices<'a> { front_offset: uint, iter: Chars<'a>, } +#[stable] impl<'a> Iterator for CharIndices<'a> { type Item = (uint, char); @@ -384,6 +390,7 @@ impl<'a> Iterator for CharIndices<'a> { } } +#[stable] impl<'a> DoubleEndedIterator for CharIndices<'a> { #[inline] fn next_back(&mut self) -> Option<(uint, char)> { @@ -465,6 +472,7 @@ impl<'a, Sep> CharSplits<'a, Sep> { } } +#[stable] impl<'a, Sep: CharEq> Iterator for CharSplits<'a, Sep> { type Item = &'a str; @@ -499,6 +507,7 @@ impl<'a, Sep: CharEq> Iterator for CharSplits<'a, Sep> { } } +#[stable] impl<'a, Sep: CharEq> DoubleEndedIterator for CharSplits<'a, Sep> { #[inline] fn next_back(&mut self) -> Option<&'a str> { @@ -540,6 +549,7 @@ impl<'a, Sep: CharEq> DoubleEndedIterator for CharSplits<'a, Sep> { } } +#[stable] impl<'a, Sep: CharEq> Iterator for CharSplitsN<'a, Sep> { type Item = &'a str; @@ -865,6 +875,7 @@ pub struct SplitStr<'a> { finished: bool } +#[stable] impl<'a> Iterator for MatchIndices<'a> { type Item = (uint, uint); @@ -881,6 +892,7 @@ impl<'a> Iterator for MatchIndices<'a> { } } +#[stable] impl<'a> Iterator for SplitStr<'a> { type Item = &'a str; @@ -1586,6 +1598,7 @@ impl<'a> Default for &'a str { fn default() -> &'a str { "" } } +#[stable] impl<'a> Iterator for Lines<'a> { type Item = &'a str; @@ -1593,11 +1606,13 @@ impl<'a> Iterator for Lines<'a> { fn next(&mut self) -> Option<&'a str> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } -} + +#[stable]} impl<'a> DoubleEndedIterator for Lines<'a> { #[inline] fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() } -} + +#[stable]} impl<'a> Iterator for LinesAny<'a> { type Item = &'a str; @@ -1605,7 +1620,8 @@ impl<'a> Iterator for LinesAny<'a> { fn next(&mut self) -> Option<&'a str> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } -} + +#[stable]} impl<'a> DoubleEndedIterator for LinesAny<'a> { #[inline] fn next_back(&mut self) -> Option<&'a str> { self.inner.next_back() } diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 7877e783ed6..0d4b2dce4c6 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -18,7 +18,7 @@ use default::Default; use fmt::Show; use fmt; use hash::{Hash, Hasher, RandomSipHasher}; -use iter::{Iterator, IteratorExt, IteratorCloneExt, FromIterator, Map, Chain, Extend}; +use iter::{Iterator, IteratorExt, FromIterator, Map, Chain, Extend}; use ops::{BitOr, BitAnd, BitXor, Sub}; use option::Option::{Some, None, self}; use result::Result::{Ok, Err}; diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index c0445fb5aea..ef9d28bbbb2 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -309,7 +309,7 @@ //! } //! ``` -#![experimental] +#![stable] pub use core_collections::{BinaryHeap, Bitv, BitvSet, BTreeMap, BTreeSet}; pub use core_collections::{DList, RingBuf, VecMap}; @@ -322,11 +322,13 @@ pub use self::hash_set::HashSet; mod hash; +#[stable] pub mod hash_map { //! A hashmap pub use super::hash::map::*; } +#[stable] pub mod hash_set { //! A hashset pub use super::hash::set::*; diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index c56acd38e81..c4e37264e2a 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -14,7 +14,7 @@ use cmp; use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult}; -use iter::ExactSizeIterator; +use iter::{IteratorExt, ExactSizeIterator}; use ops::Drop; use option::Option; use option::Option::{Some, None}; diff --git a/src/libstd/prelude/v1.rs b/src/libstd/prelude/v1.rs index f6bdcd53dff..9e9a483e1a5 100644 --- a/src/libstd/prelude/v1.rs +++ b/src/libstd/prelude/v1.rs @@ -25,11 +25,9 @@ #[stable] #[doc(no_inline)] pub use char::CharExt; #[stable] #[doc(no_inline)] pub use clone::Clone; #[stable] #[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; -#[stable] #[doc(no_inline)] pub use iter::CloneIteratorExt; #[stable] #[doc(no_inline)] pub use iter::DoubleEndedIterator; #[stable] #[doc(no_inline)] pub use iter::ExactSizeIterator; #[stable] #[doc(no_inline)] pub use iter::{Iterator, IteratorExt, Extend}; -#[stable] #[doc(no_inline)] pub use iter::{IteratorCloneExt, IteratorOrdExt}; #[stable] #[doc(no_inline)] pub use option::Option::{self, Some, None}; #[stable] #[doc(no_inline)] pub use ptr::{PtrExt, MutPtrExt}; #[stable] #[doc(no_inline)] pub use result::Result::{self, Ok, Err}; diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 7734f655ed2..e97be51fdbc 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -188,6 +188,7 @@ impl Condvar { pub fn notify_all(&self) { unsafe { self.inner.inner.notify_all() } } } +#[stable] impl Drop for Condvar { fn drop(&mut self) { unsafe { self.inner.inner.destroy() } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 338cadafff7..1ed68823a2c 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -675,6 +675,7 @@ impl Clone for Sender { } #[unsafe_destructor] +#[stable] impl Drop for Sender { fn drop(&mut self) { match *unsafe { self.inner_mut() } { @@ -768,6 +769,7 @@ impl Clone for SyncSender { } #[unsafe_destructor] +#[stable] impl Drop for SyncSender { fn drop(&mut self) { unsafe { (*self.inner.get()).drop_chan(); } @@ -1006,12 +1008,15 @@ impl select::Packet for Receiver { } } -#[unstable] -impl<'a, T: Send> Iterator for Messages<'a, T> { - fn next(&mut self) -> Option { self.rx.recv_opt().ok() } +#[stable] +impl<'a, T: Send> Iterator for Iter<'a, T> { + type Item = T; + + fn next(&mut self) -> Option { self.rx.recv().ok() } } #[unsafe_destructor] +#[stable] impl Drop for Receiver { fn drop(&mut self) { match *unsafe { self.inner_mut() } { diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index 8f85dc6e043..9ad24a5a11e 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -138,6 +138,7 @@ impl Queue { } #[unsafe_destructor] +#[stable] impl Drop for Queue { fn drop(&mut self) { unsafe { diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index b158bd69c7b..6b3dd89f33b 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -228,6 +228,7 @@ impl Mutex { } #[unsafe_destructor] +#[stable] impl Drop for Mutex { fn drop(&mut self) { // This is actually safe b/c we know that there is no further usage of @@ -291,6 +292,7 @@ impl<'mutex, T> MutexGuard<'mutex, T> { } } +#[stable] impl<'mutex, T> Deref for MutexGuard<'mutex, T> { type Target = T; @@ -298,6 +300,7 @@ impl<'mutex, T> Deref for MutexGuard<'mutex, T> { unsafe { &*self.__data.get() } } } +#[stable] impl<'mutex, T> DerefMut for MutexGuard<'mutex, T> { fn deref_mut<'a>(&'a mut self) -> &'a mut T { unsafe { &mut *self.__data.get() } @@ -305,6 +308,7 @@ impl<'mutex, T> DerefMut for MutexGuard<'mutex, T> { } #[unsafe_destructor] +#[stable] impl<'a, T> Drop for MutexGuard<'a, T> { #[inline] fn drop(&mut self) { diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 7aad5f51abe..e21aa3ef7e9 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -228,6 +228,7 @@ impl RwLock { } #[unsafe_destructor] +#[stable] impl Drop for RwLock { fn drop(&mut self) { unsafe { self.inner.lock.destroy() } @@ -327,16 +328,19 @@ impl<'rwlock, T> RwLockWriteGuard<'rwlock, T> { } } +#[stable] impl<'rwlock, T> Deref for RwLockReadGuard<'rwlock, T> { type Target = T; fn deref(&self) -> &T { unsafe { &*self.__data.get() } } } +#[stable] impl<'rwlock, T> Deref for RwLockWriteGuard<'rwlock, T> { type Target = T; fn deref(&self) -> &T { unsafe { &*self.__data.get() } } } +#[stable] impl<'rwlock, T> DerefMut for RwLockWriteGuard<'rwlock, T> { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.__data.get() } @@ -344,6 +348,7 @@ impl<'rwlock, T> DerefMut for RwLockWriteGuard<'rwlock, T> { } #[unsafe_destructor] +#[stable] impl<'a, T> Drop for RwLockReadGuard<'a, T> { fn drop(&mut self) { unsafe { self.__lock.lock.read_unlock(); } @@ -351,6 +356,7 @@ impl<'a, T> Drop for RwLockReadGuard<'a, T> { } #[unsafe_destructor] +#[stable] impl<'a, T> Drop for RwLockWriteGuard<'a, T> { fn drop(&mut self) { self.__lock.poison.done(&self.__poison); diff --git a/src/libstd/sync/semaphore.rs b/src/libstd/sync/semaphore.rs index c0ff674ba0f..505819fbf8a 100644 --- a/src/libstd/sync/semaphore.rs +++ b/src/libstd/sync/semaphore.rs @@ -99,6 +99,7 @@ impl Semaphore { } #[unsafe_destructor] +#[stable] impl<'a> Drop for SemaphoreGuard<'a> { fn drop(&mut self) { self.sem.release(); diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index 63112327415..cc82d38ae2a 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -423,6 +423,7 @@ impl JoinGuard { } #[unsafe_destructor] +#[stable] impl Drop for JoinGuard { fn drop(&mut self) { if !self.joined {