Skip to content

Stabilize some stragglers in std::option #23771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl<T> Option<T> {
/// assert_eq!(x.ok_or(0), Err(0));
/// ```
#[inline]
#[unstable(feature = "core")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn ok_or<E>(self, err: E) -> Result<T, E> {
match self {
Some(v) => Ok(v),
Expand All @@ -502,7 +502,7 @@ impl<T> Option<T> {
/// assert_eq!(x.ok_or_else(|| 0), Err(0));
/// ```
#[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> {
match self {
Some(v) => Ok(v),
Expand Down Expand Up @@ -548,8 +548,7 @@ impl<T> Option<T> {
/// assert_eq!(x.iter_mut().next(), None);
/// ```
#[inline]
#[unstable(feature = "core",
reason = "waiting for iterator conventions")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<T> {
IterMut { inner: Item { opt: self.as_mut() } }
}
Expand Down Expand Up @@ -721,13 +720,11 @@ impl<T> Option<T> {
}
}

impl<'a, T: Clone, D: Deref<Target=T>> Option<D> {
/// Maps an Option<D> to an Option<T> by dereffing and cloning the contents of the Option.
/// Useful for converting an Option<&T> to an Option<T>.
#[unstable(feature = "core",
reason = "recently added as part of collections reform")]
impl<'a, T: Clone> Option<&'a T> {
/// Maps an Option<&T> to an Option<T> by cloning the contents of the Option.
#[stable(feature = "rust1", since = "1.0.0")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't really felt the need to stabilize this in the past as it seems more niche than IteratorExt::cloned. Did you have some specific use-cases in mind?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No burning need here. The motivation is exactly the same as for iterators.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(The fact that iterators have a stable version of this method, to me, justifies it as a somewhat conventional thing to provide, in that there's not much additional cognitive overhead here. YMMV)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm cool with that!

pub fn cloned(self) -> Option<T> {
self.map(|t| t.deref().clone())
self.map(|t| t.clone())
}
}

Expand Down