diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-04-17 14:31:30 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-04-17 16:37:30 -0700 |
| commit | 8f5b5f94dcdb9884737dfbc8efd893d1d70f0b14 (patch) | |
| tree | 58fb1909672648a664d2b02125d1d6c94191b075 /src/libcore | |
| parent | 9d2ac9b1e15f2a2c0963060f476d0478be1acdc3 (diff) | |
| download | rust-8f5b5f94dcdb9884737dfbc8efd893d1d70f0b14.tar.gz rust-8f5b5f94dcdb9884737dfbc8efd893d1d70f0b14.zip | |
std: Add Default/IntoIterator/ToOwned to the prelude
This is an implementation of [RFC 1030][rfc] which adds these traits to the prelude and additionally removes all inherent `into_iter` methods on collections in favor of the trait implementation (which is now accessible by default). [rfc]: https://github.com/rust-lang/rfcs/pull/1030 This is technically a breaking change due to the prelude additions and removal of inherent methods, but it is expected that essentially no code breaks in practice. [breaking-change] Closes #24538
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/hash/mod.rs | 1 | ||||
| -rw-r--r-- | src/libcore/hash/sip.rs | 1 | ||||
| -rw-r--r-- | src/libcore/option.rs | 43 | ||||
| -rw-r--r-- | src/libcore/prelude.rs | 5 | ||||
| -rw-r--r-- | src/libcore/result.rs | 43 |
5 files changed, 50 insertions, 43 deletions
diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 553e0c0dfe6..e848a44e01c 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -62,7 +62,6 @@ use prelude::*; -use default::Default; use mem; pub use self::sip::SipHasher; diff --git a/src/libcore/hash/sip.rs b/src/libcore/hash/sip.rs index 6820a7025fc..0bff9b0ba42 100644 --- a/src/libcore/hash/sip.rs +++ b/src/libcore/hash/sip.rs @@ -15,7 +15,6 @@ #![allow(deprecated)] // until the next snapshot for inherent wrapping ops use prelude::*; -use default::Default; use super::Hasher; /// An implementation of SipHash 2-4. diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 4c784a579da..d1bc24bd9ba 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -551,25 +551,6 @@ impl<T> Option<T> { IterMut { inner: Item { opt: self.as_mut() } } } - /// Returns a consuming iterator over the possibly contained value. - /// - /// # Examples - /// - /// ``` - /// let x = Some("string"); - /// let v: Vec<&str> = x.into_iter().collect(); - /// assert_eq!(v, ["string"]); - /// - /// let x = None; - /// let v: Vec<&str> = x.into_iter().collect(); - /// assert!(v.is_empty()); - /// ``` - #[inline] - #[stable(feature = "rust1", since = "1.0.0")] - pub fn into_iter(self) -> IntoIter<T> { - IntoIter { inner: Item { opt: self } } - } - ///////////////////////////////////////////////////////////////////////// // Boolean operations on the values, eager and lazy ///////////////////////////////////////////////////////////////////////// @@ -770,6 +751,30 @@ impl<T> Default for Option<T> { fn default() -> Option<T> { None } } +#[stable(feature = "rust1", since = "1.0.0")] +impl<T> IntoIterator for Option<T> { + type Item = T; + type IntoIter = IntoIter<T>; + + /// Returns a consuming iterator over the possibly contained value. + /// + /// # Examples + /// + /// ``` + /// let x = Some("string"); + /// let v: Vec<&str> = x.into_iter().collect(); + /// assert_eq!(v, ["string"]); + /// + /// let x = None; + /// let v: Vec<&str> = x.into_iter().collect(); + /// assert!(v.is_empty()); + /// ``` + #[inline] + fn into_iter(self) -> IntoIter<T> { + IntoIter { inner: Item { opt: self } } + } +} + ///////////////////////////////////////////////////////////////////////////// // The Option Iterators ///////////////////////////////////////////////////////////////////////////// diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index e60bc494081..a4d529ad47d 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -37,11 +37,10 @@ pub use char::CharExt; pub use clone::Clone; pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; pub use convert::{AsRef, AsMut, Into, From}; +pub use default::Default; +pub use iter::IntoIterator; pub use iter::{Iterator, DoubleEndedIterator, Extend, ExactSizeIterator}; pub use option::Option::{self, Some, None}; pub use result::Result::{self, Ok, Err}; pub use slice::SliceExt; pub use str::StrExt; - -#[allow(deprecated)] pub use slice::AsSlice; -#[allow(deprecated)] pub use str::Str; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 26bc653b26f..3ffff8de892 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -547,25 +547,6 @@ impl<T, E> Result<T, E> { IterMut { inner: self.as_mut().ok() } } - /// Returns a consuming iterator over the possibly contained value. - /// - /// # Examples - /// - /// ``` - /// let x: Result<u32, &str> = Ok(5); - /// let v: Vec<u32> = x.into_iter().collect(); - /// assert_eq!(v, [5]); - /// - /// let x: Result<u32, &str> = Err("nothing!"); - /// let v: Vec<u32> = x.into_iter().collect(); - /// assert_eq!(v, []); - /// ``` - #[inline] - #[stable(feature = "rust1", since = "1.0.0")] - pub fn into_iter(self) -> IntoIter<T> { - IntoIter { inner: self.ok() } - } - //////////////////////////////////////////////////////////////////////// // Boolean operations on the values, eager and lazy ///////////////////////////////////////////////////////////////////////// @@ -807,6 +788,30 @@ impl<T, E> AsSlice<T> for Result<T, E> { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl<T, E> IntoIterator for Result<T, E> { + type Item = T; + type IntoIter = IntoIter<T>; + + /// Returns a consuming iterator over the possibly contained value. + /// + /// # Examples + /// + /// ``` + /// let x: Result<u32, &str> = Ok(5); + /// let v: Vec<u32> = x.into_iter().collect(); + /// assert_eq!(v, [5]); + /// + /// let x: Result<u32, &str> = Err("nothing!"); + /// let v: Vec<u32> = x.into_iter().collect(); + /// assert_eq!(v, []); + /// ``` + #[inline] + fn into_iter(self) -> IntoIter<T> { + IntoIter { inner: self.ok() } + } +} + ///////////////////////////////////////////////////////////////////////////// // The Result Iterators ///////////////////////////////////////////////////////////////////////////// |
