Skip to content

Commit

Permalink
Rollup merge of rust-lang#62379 - GuillaumeGomez:option-doc-links, r=…
Browse files Browse the repository at this point in the history
…QuietMisdreavus

Add missing links in Option documentation

r? @rust-lang/docs
  • Loading branch information
Centril committed Jul 7, 2019
2 parents 719eeb2 + 02886e2 commit c512829
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<T> Option<T> {
}


/// Converts from `Pin<&Option<T>>` to `Option<Pin<&T>>`
/// Converts from [`Pin`]`<&Option<T>>` to `Option<`[`Pin`]`<&T>>`.
#[inline]
#[stable(feature = "pin", since = "1.33.0")]
pub fn as_pin_ref<'a>(self: Pin<&'a Option<T>>) -> Option<Pin<&'a T>> {
Expand All @@ -272,7 +272,7 @@ impl<T> Option<T> {
}
}

/// Converts from `Pin<&mut Option<T>>` to `Option<Pin<&mut T>>`
/// Converts from [`Pin`]`<&mut Option<T>>` to `Option<`[`Pin`]`<&mut T>>`.
#[inline]
#[stable(feature = "pin", since = "1.33.0")]
pub fn as_pin_mut<'a>(self: Pin<&'a mut Option<T>>) -> Option<Pin<&'a mut T>> {
Expand Down Expand Up @@ -626,14 +626,14 @@ impl<T> Option<T> {
}
}

/// Returns `None` if the option is `None`, otherwise calls `predicate`
/// Returns [`None`] if the option is [`None`], otherwise calls `predicate`
/// with the wrapped value and returns:
///
/// - `Some(t)` if `predicate` returns `true` (where `t` is the wrapped
/// - [`Some(t)`] if `predicate` returns `true` (where `t` is the wrapped
/// value), and
/// - `None` if `predicate` returns `false`.
/// - [`None`] if `predicate` returns `false`.
///
/// This function works similar to `Iterator::filter()`. You can imagine
/// This function works similar to [`Iterator::filter()`]. You can imagine
/// the `Option<T>` being an iterator over one or zero elements. `filter()`
/// lets you decide which elements to keep.
///
Expand All @@ -648,6 +648,10 @@ impl<T> Option<T> {
/// assert_eq!(Some(3).filter(is_even), None);
/// assert_eq!(Some(4).filter(is_even), Some(4));
/// ```
///
/// [`None`]: #variant.None
/// [`Some(t)`]: #variant.Some
/// [`Iterator::filter()`]: ../../std/iter/trait.Iterator.html#method.filter
#[inline]
#[stable(feature = "option_filter", since = "1.27.0")]
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
Expand Down Expand Up @@ -986,17 +990,25 @@ impl<T: Deref> Option<T> {
/// Converts from `&Option<T>` to `Option<&T::Target>`.
///
/// Leaves the original Option in-place, creating a new one with a reference
/// to the original one, additionally coercing the contents via `Deref`.
/// to the original one, additionally coercing the contents via [`Deref`].
///
/// [`Deref`]: ../../std/ops/trait.Deref.html
pub fn deref(&self) -> Option<&T::Target> {
self.as_ref().map(|t| t.deref())
}
}

impl<T, E> Option<Result<T, E>> {
/// Transposes an `Option` of a `Result` into a `Result` of an `Option`.
/// Transposes an `Option` of a [`Result`] into a [`Result`] of an `Option`.
///
/// `None` will be mapped to `Ok(None)`.
/// `Some(Ok(_))` and `Some(Err(_))` will be mapped to `Ok(Some(_))` and `Err(_)`.
/// [`None`] will be mapped to [`Ok`]`(`[`None`]`)`.
/// [`Some`]`(`[`Ok`]`(_))` and [`Some`]`(`[`Err`]`(_))` will be mapped to
/// [`Ok`]`(`[`Some`]`(_))` and [`Err`]`(_)`.
///
/// [`None`]: #variant.None
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
/// [`Some`]: #variant.Some
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
///
/// # Examples
///
Expand Down

0 comments on commit c512829

Please sign in to comment.