rollup merge of #23771: aturon/stab-straggle-1

Marks as `#[stable}`:

* `ok_or`
* `ok_or_else`
* `iter_mut`
* `cloned`

Similarly to `IteratorExt::cloned`, the `cloned` method is pared down to
work only on `Option<&T>`. Thus, this is a:

[breaking-change]

r? @alexcrichton
This commit is contained in:
Alex Crichton
2015-03-27 10:07:52 -07:00

View File

@@ -480,7 +480,7 @@ impl<T> Option<T> {
/// assert_eq!(x.ok_or(0), Err(0)); /// assert_eq!(x.ok_or(0), Err(0));
/// ``` /// ```
#[inline] #[inline]
#[unstable(feature = "core")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn ok_or<E>(self, err: E) -> Result<T, E> { pub fn ok_or<E>(self, err: E) -> Result<T, E> {
match self { match self {
Some(v) => Ok(v), Some(v) => Ok(v),
@@ -502,7 +502,7 @@ impl<T> Option<T> {
/// assert_eq!(x.ok_or_else(|| 0), Err(0)); /// assert_eq!(x.ok_or_else(|| 0), Err(0));
/// ``` /// ```
#[inline] #[inline]
#[unstable(feature = "core")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E> { pub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E> {
match self { match self {
Some(v) => Ok(v), Some(v) => Ok(v),
@@ -548,8 +548,7 @@ impl<T> Option<T> {
/// assert_eq!(x.iter_mut().next(), None); /// assert_eq!(x.iter_mut().next(), None);
/// ``` /// ```
#[inline] #[inline]
#[unstable(feature = "core", #[stable(feature = "rust1", since = "1.0.0")]
reason = "waiting for iterator conventions")]
pub fn iter_mut(&mut self) -> IterMut<T> { pub fn iter_mut(&mut self) -> IterMut<T> {
IterMut { inner: Item { opt: self.as_mut() } } IterMut { inner: Item { opt: self.as_mut() } }
} }
@@ -721,13 +720,11 @@ impl<T> Option<T> {
} }
} }
impl<'a, T: Clone, D: Deref<Target=T>> Option<D> { impl<'a, T: Clone> Option<&'a T> {
/// Maps an Option<D> to an Option<T> by dereffing and cloning the contents of the Option. /// Maps an Option<&T> to an Option<T> by cloning the contents of the Option.
/// Useful for converting an Option<&T> to an Option<T>. #[stable(feature = "rust1", since = "1.0.0")]
#[unstable(feature = "core",
reason = "recently added as part of collections reform")]
pub fn cloned(self) -> Option<T> { pub fn cloned(self) -> Option<T> {
self.map(|t| t.deref().clone()) self.map(|t| t.clone())
} }
} }