Skip to content

Commit

Permalink
fixes to Option::{zip,zip_with}
Browse files Browse the repository at this point in the history
- remove `#[inline]` attributes (see #69997 (comment))
- fill tracking issue in `#[unstable]` attributes
- slightly improve the docs
  • Loading branch information
WaffleLapkin committed Mar 18, 2020
1 parent a5206f9 commit d36d3fa
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,8 @@ impl<T> Option<T> {

/// Zips `self` with another `Option`.
///
/// Returns `Some((_, _))` when both `self` and `other`
/// are `Some(_)`, otherwise return `None`.
/// If `self` is `Some(s)` and other is `Some(o)`, this method returns `Some((s, o))`.
/// Otherwise, `None` is returned.
///
/// # Examples
///
Expand All @@ -930,16 +930,15 @@ impl<T> Option<T> {
/// assert_eq!(x.zip(y), Some((1, "hi")));
/// assert_eq!(x.zip(z), None);
/// ```
#[inline]
#[unstable(feature = "option_zip", issue = "none")]
#[unstable(feature = "option_zip", issue = "70086")]
pub fn zip<U>(self, other: Option<U>) -> Option<(T, U)> {
self.zip_with(other, |a, b| (a, b))
}

/// Zips `self` and another `Option` with function `f`.
///
/// Returns `Some(_)` when both `self` and `other`
/// are `Some(_)`, otherwise return `None`.
/// If `self` is `Some(s)` and other is `Some(o)`, this method returns `Some(f(s, o))`.
/// Otherwise, `None` is returned.
///
/// # Examples
///
Expand All @@ -958,14 +957,13 @@ impl<T> Option<T> {
/// }
/// }
///
/// let x = Some(17.);
/// let y = Some(42.);
/// let x = Some(17.5);
/// let y = Some(42.7);
///
/// assert_eq!(x.zip_with(y, Point::new), Some(Point { x: 17., y: 42. }));
/// assert_eq!(x.zip_with(y, Point::new), Some(Point { x: 17.5, y: 42.7 }));
/// assert_eq!(x.zip_with(None, Point::new), None);
/// ```
#[inline]
#[unstable(feature = "option_zip", issue = "none")]
#[unstable(feature = "option_zip", issue = "70086")]
pub fn zip_with<U, F, R>(self, other: Option<U>, f: F) -> Option<R>
where
F: FnOnce(T, U) -> R,
Expand Down

0 comments on commit d36d3fa

Please sign in to comment.