Skip to content

Commit

Permalink
Rollup merge of #42163 - projektir:option_links, r=frewsxcv
Browse files Browse the repository at this point in the history
Adding links to option::Option

Just adding some links.
  • Loading branch information
frewsxcv authored May 23, 2017
2 parents f37b34d + 6e27bd8 commit aa7762f
Showing 1 changed file with 60 additions and 26 deletions.
86 changes: 60 additions & 26 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<T> Option<T> {
// Querying the contained values
/////////////////////////////////////////////////////////////////////////

/// Returns `true` if the option is a `Some` value.
/// Returns `true` if the option is a [`Some`] value.
///
/// # Examples
///
Expand All @@ -185,6 +185,8 @@ impl<T> Option<T> {
/// let x: Option<u32> = None;
/// assert_eq!(x.is_some(), false);
/// ```
///
/// [`Some`]: #variant.Some
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_some(&self) -> bool {
Expand All @@ -194,7 +196,7 @@ impl<T> Option<T> {
}
}

/// Returns `true` if the option is a `None` value.
/// Returns `true` if the option is a [`None`] value.
///
/// # Examples
///
Expand All @@ -205,6 +207,8 @@ impl<T> Option<T> {
/// let x: Option<u32> = None;
/// assert_eq!(x.is_none(), true);
/// ```
///
/// [`None`]: #variant.None
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_none(&self) -> bool {
Expand Down Expand Up @@ -269,13 +273,14 @@ impl<T> Option<T> {
// Getting to contained values
/////////////////////////////////////////////////////////////////////////

/// Unwraps an option, yielding the content of a `Some`.
/// Unwraps an option, yielding the content of a [`Some`].
///
/// # Panics
///
/// Panics if the value is a [`None`] with a custom panic message provided by
/// `msg`.
///
/// [`Some`]: #variant.Some
/// [`None`]: #variant.None
///
/// # Examples
Expand All @@ -298,16 +303,17 @@ impl<T> Option<T> {
}
}

/// Moves the value `v` out of the `Option<T>` if it is `Some(v)`.
/// Moves the value `v` out of the `Option<T>` if it is [`Some(v)`].
///
/// In general, because this function may panic, its use is discouraged.
/// Instead, prefer to use pattern matching and handle the `None`
/// Instead, prefer to use pattern matching and handle the [`None`]
/// case explicitly.
///
/// # Panics
///
/// Panics if the self value equals [`None`].
///
/// [`Some(v)`]: #variant.Some
/// [`None`]: #variant.None
///
/// # Examples
Expand Down Expand Up @@ -395,7 +401,9 @@ impl<T> Option<T> {
}

/// Applies a function to the contained value (if any),
/// or returns a `default` (if not).
/// or returns a [`default`][] (if not).
///
/// [`default`]: ../default/trait.Default.html#tymethod.default
///
/// # Examples
///
Expand All @@ -416,7 +424,9 @@ impl<T> Option<T> {
}

/// Applies a function to the contained value (if any),
/// or computes a `default` (if not).
/// or computes a [`default`][] (if not).
///
/// [`default`]: ../default/trait.Default.html#tymethod.default
///
/// # Examples
///
Expand All @@ -438,12 +448,14 @@ impl<T> Option<T> {
}
}

/// Transforms the `Option<T>` into a [`Result<T, E>`], mapping `Some(v)` to
/// [`Ok(v)`] and `None` to [`Err(err)`][Err].
/// Transforms the `Option<T>` into a [`Result<T, E>`], mapping [`Some(v)`] to
/// [`Ok(v)`] and [`None`] to [`Err(err)`].
///
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
/// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok
/// [Err]: ../../std/result/enum.Result.html#variant.Err
/// [`Err(err)`]: ../../std/result/enum.Result.html#variant.Err
/// [`None`]: #variant.None
/// [`Some(v)`]: #variant.Some
///
/// # Examples
///
Expand All @@ -463,12 +475,14 @@ impl<T> Option<T> {
}
}

/// Transforms the `Option<T>` into a [`Result<T, E>`], mapping `Some(v)` to
/// [`Ok(v)`] and `None` to [`Err(err())`][Err].
/// Transforms the `Option<T>` into a [`Result<T, E>`], mapping [`Some(v)`] to
/// [`Ok(v)`] and [`None`] to [`Err(err())`].
///
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
/// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok
/// [Err]: ../../std/result/enum.Result.html#variant.Err
/// [`Err(err())`]: ../../std/result/enum.Result.html#variant.Err
/// [`None`]: #variant.None
/// [`Some(v)`]: #variant.Some
///
/// # Examples
///
Expand Down Expand Up @@ -534,7 +548,9 @@ impl<T> Option<T> {
// Boolean operations on the values, eager and lazy
/////////////////////////////////////////////////////////////////////////

/// Returns `None` if the option is `None`, otherwise returns `optb`.
/// Returns [`None`] if the option is [`None`], otherwise returns `optb`.
///
/// [`None`]: #variant.None
///
/// # Examples
///
Expand Down Expand Up @@ -564,11 +580,13 @@ impl<T> Option<T> {
}
}

/// Returns `None` if the option is `None`, otherwise calls `f` with the
/// Returns [`None`] if the option is [`None`], otherwise calls `f` with the
/// wrapped value and returns the result.
///
/// Some languages call this operation flatmap.
///
/// [`None`]: #variant.None
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -645,9 +663,11 @@ impl<T> Option<T> {
// Entry-like operations to insert if None and return a reference
/////////////////////////////////////////////////////////////////////////

/// Inserts `v` into the option if it is `None`, then
/// Inserts `v` into the option if it is [`None`], then
/// returns a mutable reference to the contained value.
///
/// [`None`]: #variant.None
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -678,9 +698,11 @@ impl<T> Option<T> {
}
}

/// Inserts a value computed from `f` into the option if it is `None`, then
/// Inserts a value computed from `f` into the option if it is [`None`], then
/// returns a mutable reference to the contained value.
///
/// [`None`]: #variant.None
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -715,7 +737,9 @@ impl<T> Option<T> {
// Misc
/////////////////////////////////////////////////////////////////////////

/// Takes the value out of the option, leaving a `None` in its place.
/// Takes the value out of the option, leaving a [`None`] in its place.
///
/// [`None`]: #variant.None
///
/// # Examples
///
Expand Down Expand Up @@ -757,16 +781,16 @@ impl<'a, T: Clone> Option<&'a T> {
impl<T: Default> Option<T> {
/// Returns the contained value or a default
///
/// Consumes the `self` argument then, if `Some`, returns the contained
/// value, otherwise if `None`, returns the default value for that
/// Consumes the `self` argument then, if [`Some`], returns the contained
/// value, otherwise if [`None`], returns the default value for that
/// type.
///
/// # Examples
///
/// Convert a string to an integer, turning poorly-formed strings
/// into 0 (the default value for integers). `parse` converts
/// a string to any other type that implements `FromStr`, returning
/// `None` on error.
/// into 0 (the default value for integers). [`parse`] converts
/// a string to any other type that implements [`FromStr`], returning
/// [`None`] on error.
///
/// ```
/// let good_year_from_input = "1909";
Expand All @@ -777,6 +801,11 @@ impl<T: Default> Option<T> {
/// assert_eq!(1909, good_year);
/// assert_eq!(0, bad_year);
/// ```
///
/// [`Some`]: #variant.Some
/// [`None`]: #variant.None
/// [`parse`]: ../../std/primitive.str.html#method.parse
/// [`FromStr`]: ../../std/str/trait.FromStr.html
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_or_default(self) -> T {
Expand All @@ -801,7 +830,9 @@ fn expect_failed(msg: &str) -> ! {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Option<T> {
/// Returns None.
/// Returns [`None`].
///
/// [`None`]: #variant.None
#[inline]
fn default() -> Option<T> { None }
}
Expand Down Expand Up @@ -1020,8 +1051,8 @@ unsafe impl<A> TrustedLen for IntoIter<A> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// Takes each element in the `Iterator`: if it is `None`, no further
/// elements are taken, and the `None` is returned. Should no `None` occur, a
/// Takes each element in the [`Iterator`]: if it is [`None`], no further
/// elements are taken, and the [`None`] is returned. Should no [`None`] occur, a
/// container with the values of each `Option` is returned.
///
/// Here is an example which increments every integer in a vector,
Expand All @@ -1037,6 +1068,9 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// ).collect();
/// assert!(res == Some(vec![2, 3]));
/// ```
///
/// [`Iterator`]: ../iter/trait.Iterator.html
/// [`None`]: enum.Option.html#variant.None
#[inline]
fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {
// FIXME(#11084): This could be replaced with Iterator::scan when this
Expand Down

0 comments on commit aa7762f

Please sign in to comment.