// Querying the contained values
/////////////////////////////////////////////////////////////////////////
- /// Returns `true` if the option is a `Some` value.
+ /// Returns `true` if the option is a [`Some`] value.
///
/// # Examples
///
/// 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 {
}
}
- /// Returns `true` if the option is a `None` value.
+ /// Returns `true` if the option is a [`None`] value.
///
/// # Examples
///
/// 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 {
// 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
}
}
- /// 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
}
/// 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
///
}
/// 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
///
}
}
- /// 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
///
}
}
- /// 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
///
// 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
///
}
}
- /// 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
///
/// ```
// 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
///
/// ```
}
}
- /// 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
///
/// ```
// 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
///
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";
/// 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 {
#[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 }
}
#[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,
/// ).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